https://kotlinlang.org logo
#codereview
Title
# codereview
e

Eugen Martynov

05/28/2020, 9:25 AM
Do you prefer
Copy code
abstract class A {
  abstract fun doSomething()
}
with
Copy code
object: A() {
  override fun doSomething(){}
}
or
Copy code
class A(private val doSomething: () -> Unit)
with
Copy code
A() {...}
?
a

araqnid

05/28/2020, 9:46 AM
Usually the first, I don’t remember ever using a constructor with a trailing {…} block (took me a few seconds to parse what was going on)
☝️ 1
although if A is an interface with a single method, can’t it now be satisfied by a lambda? (I know that used to be just for Java SAM interfaces, but I thought it had been extended to Kotlin ones too)
3
m

Matteo Mirk

05/28/2020, 9:50 AM
If understand correctly you’re choosing between two styles to implement the Strategy pattern?
e

Eugen Martynov

05/28/2020, 10:37 AM
it is scroll listener class for pagination, it calculates when next page should be loaded and call the abstract function