I'm trying to do a Facade of my interfaces to abstract real types and omit need to name all of them directly. I ended up with this:
class Facade : ILeft by LeftImpl(), IRight by RightImpl()
ILeft
and IRight
are interfaces and I instantiate their implementations. This is in general solution I was looking for and it worked.
BUT
Let's say, I know, I will use most of the time only ILeft, or IRight. There are cases where I use them both, but most of the time, I'll use just one. Thus I would like to make them lazy, but how?
1) It's possible to use instance provided in the constructor, but that requires an instance.
2) If I try to define:
class Facade : ILeft by left, IRight by right {
val left by lazy { LeftImpl() }
val right by lazy { RightImpl() }
}
The left
and right
are inaccessible in the class declaration.
I can make the implementations lazy inside, that's also a possibility. But I'm trying to find a way, to write this out of the box, just by kotlin.
Any ideas how to have Facade object with just ILeft actually initialized by implementation?