edwardwongtl
04/11/2018, 3:48 AMfun doSth(action: Mode.() -> Unit)
?
But Mode
contains only functions, no properties.
Although it is completely fine to create instance of Mode
and pass it to action(mode)
, it just doesn't quite make sense for me to create such a instance.gildor
04/11/2018, 4:51 AMedwardwongtl
04/11/2018, 5:06 AMadd
, minus
inside fun doSth
fun doSth(action: Mode.() -> Unit) { ... }
doSth {
add() // OK
minus() // OK
multiple() // Not ok
}
gildor
04/11/2018, 5:41 AMedwardwongtl
04/11/2018, 5:41 AMgildor
04/11/2018, 5:42 AMedwardwongtl
04/11/2018, 5:42 AMfun doSth(...) {
action(mode) // Don't want to pass in mode
}
Mode
consist of pure functions, I'm just using it for function grouping purpose in this case.interface Mode
instead of class Mode
?gildor
04/11/2018, 5:54 AMclass/interface Mode {
fun add()
fun minus()
}
class MultipleMode: Mode {
fun multiple()
}
edwardwongtl
04/11/2018, 5:56 AM