Increase var visibility


#1

Good day, is it possible to only increase var visiblity (that is, I don’t wish to alter the var behavior in any way, I just wish to make it public). That is, say you have a class:

AbstractLazyRecycler : FrameLayout {
    protected open var layoutManager: RecyclerView.LayoutManager
    get()= recycler.layoutManager
    set(value) { recycler.layoutManager = value }
}

which you can either extend to implement your own component (and then layoutManager must not be public), or you can compose it inside of a layout your component extend (and in that case the layoutManager must be public). I was thinking

LazyRecycler: AbstractLazyRecycler {
    public var layoutManager
}

but I’m getting compiler errors no matter what I enter :wink: Thanks!


#2

Wouldn’t it be better to use delegation in such cases? Inheritance is mostly about polymorphism and not so much about reusing code.


#3

Yes, delegation is definitely better than inheritance. Yet, the pesky UI world mandates that all visual components are Views, which would mean that I would have to wrap the LazyRecycler in another ViewGroup (just to hide its API), which decreases the UI performance :frowning: