I am working on my builder hierarchy and I'm stuck on a design / implementation point.
I would like to have a shared, private object called “builder”, which is an HDSBuilder (from a Java framework) and use that single instance in all sub class instances.
For example:
abstract class N
abstract class TestNode(): N() {
var builder : HDSBuilder
open protected fun initNode<T: N>(tag: T, init: T.() -> Unit): T {
builder.pushNode(“test”)
tag.init()
builder.popNode()
return tag
}
fun assert(init: AssertNode.() ->Unit) = initNode(AssertNode(), init)
}
class AssertNode(): TestNode() {
class TestLIstRoot() : TestNode() {
override var builder : HDSBuilder = HDSBuilder()
fun test(init: TestNode.() -> Unit) = initNode(TestListRoot(), init)
override fun initNode<T: N>(tag: T, init: T.() -> Unit): T {
builder.pushNode(“test”)
tag.init()
builder.popNode()
return tag
}
}
What is the best way to do this in Kotlin?
– Randy