Ruckus
04/12/2022, 6:47 PMRuckus
04/12/2022, 6:49 PMobject A {
val a = ...
}
object B : A {
val b = ...
}
object C : B {
val c = ...
}
use(C.b)
The best I've come up with is
interface A {
val a: Thing
companion object : A {
override val a = ...
}
}
interface B : A {
val b: Thing
companion object : B, A by A {
override val b = ...
}
}
interface C : B {
val c: Thing
companion object : C, B by B {
override val c = ...
}
}
but it's rather tedious.Paul Griffith
04/12/2022, 6:51 PMYoussef Shoaib [MOD]
04/12/2022, 6:52 PMephemient
04/12/2022, 6:52 PMsealed class A {
val a = "..."
companion object : A()
}
sealed class B : A() {
val b = "..."
companion object : B()
}
sealed class C : B() {
val c = "..."
companion object : C()
}
but I agree with above, this does not seem like a great patternRuckus
04/12/2022, 6:54 PMRuckus
04/12/2022, 6:56 PMYoussef Shoaib [MOD]
04/12/2022, 6:57 PMRuckus
04/12/2022, 7:00 PMobject PlatformStyles {
val header = cssClass("header")
val content = cssClass("content")
val foooter = cssClass("footer")
val baseColor = CssProperty<CssColor>("base-color")
val accentColor = CssProperty<CssColor>("accent-color")
}
object LibraryStyles : PlatformStyles {
val sponsorBox = cssClass("sponsor")
val sponsorBias = CssProperty<Bias>("sponsor-bias")
}
And it would be used
app.style = LibraryStyles {
header {
baseColor = color("red")
}
content {
accentColor = color("orange")
sponsorBox {
sponsorBias = Bias.Wide
}
}
}
Youssef Shoaib [MOD]
04/12/2022, 7:01 PMMyExtra
and I add the methods I want as extensions on MyExtra but while requiring a context of the normal DSL class. Then simply whenever I want to give the user access to those methods, I put them in a context(DslClass, MyExtra)
and let the magic happenephemient
04/12/2022, 7:02 PMobject
, and even plain old receivers may work if you have a simple setup, e.g.
interface A { companion object }
val A.a get() = ...
interface B : A { companion object }
val B.b get() = ...
interface C : B { companion object }
val C.c get() = ...
Ruckus
04/12/2022, 7:06 PMRuckus
04/12/2022, 7:10 PMRuckus
04/12/2022, 7:13 PMYoussef Shoaib [MOD]
04/14/2022, 3:54 PM