Closed Cotel closed 7 years ago
Solves #13
It is ready to be merged, BUT I think the example can be improved.
By using an anonymous implementation for the Observer :
interface Observer<in T> { fun onValueChange(newValue: T, oldValue: T) } class Shop { private val observer = object : Observer<Int> { override fun onValueChange(newValue: Int, oldValue: Int) = when { newValue > oldValue -> println(...) else -> println(...) } } private var currentCustomers by Delegates.observable(0) { _, old, new -> observer.onValueChange(new, old) } // ... }
Or even removing the Observer interface :
class Shop { private var currentCustomers by Delegates.observable(0) { _, old, new -> onValueChange(new, old) } private fun onValueChange(newValue: Int, oldValue: Int) = // ... // ... }
Although this last one may not respect the SOLID rules 🤔
What do you think? Should we change it before merging?
oh fuck, don't care
Solves #13
It is ready to be merged, BUT I think the example can be improved.
By using an anonymous implementation for the Observer :
Or even removing the Observer interface :
Although this last one may not respect the SOLID rules 🤔
What do you think? Should we change it before merging?