4 ms·
I have looked at the template method pattern, but to me this just sounds like what you really want is composition. open class Importer { fun import() {
by princeofdevils 4y ago
I have looked at the template method pattern, but to me this just sounds like what you really want is composition.
open class Importer {
fun import() {
// do common logic...
val parsed = parse() // call specialized behaviour
}
open fun parse() { ... }
}
Vs.
class Importer(private val parser: Parser) {
fun import() {
// do common logic...
val parsed = parser.Parse() // call specialized behaviour
}
}
In my experience, using inheritance can quickly make things worse.
(Go seems to agree, there is no inheritance in Go, only composition.)