Does anyone know if and when this will ever be added?
I am trying to implement a form of multi-inheritance where a class implements several interfaces from other modules. Perhaps there is another way. Consider the following example.
I have a BaseFragment
in my core library module that extends from the support Fragment
class.
class BaseFragment:Fragment(){ ... }
Then I have one module that handles fragment routing and one for fragment styling configuration where I have an interfaces that I want the BaseFragment to conform to:
interface IFragmentRoutable {
fun didReceiveRouteVars(vars: List<RouteVar>?)
}
interface IFragmentStyleable {
// NOTE: only showing one of the interface methods
fun onStyleConfigUpdated()
}
In order solve this, I can simply create extension functions for my BaseFragment, within each respective module to allow it to implement the respective methods like so:
// RouteVar class comes from Routing module
fun BaseFragment.didReceiveRouteVars(vars: List<RouteVar>?){}
fun BaseFragment.onStyleConfigUpdated(){
// code that uses stuff from Style Config module
}
But then BaseFragment would not be implementing the IFragmentRoutable
or IFragmentStyleable
interface. Also I have heard and read that using extension functions for something like this is not the best practice anyways.
The other option of course would be to just make a base class for each; BaseRoutableFragment
BaseStyleableFragment
where each implements their respective interfaces, but then I also need a base class for the combination of these; BaseRoutableStyleableFragment
which yields redundant code, which I would like to avoid.
I want to be able to make BaseFragment
implement the desired interface within the scope of each module.
Something like this:
// In Routing module
extend class BaseFragment : IFragmentRoutable {
didReceiveRouteVars(vars: List<RouteVar>?){}
}
But unfortunately that is impossible, but perhaps there is another approach that Im missing?