Hello Joost and thank you for you comment.
“Why would those classes be able to call on those methods?”
I completely agree with you, that’s why I added 2 links at the bottom, that will point to that “problem”.
“…to hide your entire logic wihtin the interface just because you want to use multiple abstract classes at the same time.”
True, but how can I achieve that? Let’s use a LEGO analogy, I have a car and a bike, the first use 4 wheels and 4 doors the second only 2 wheels. I don’t care how the pieces are made, I just want to use them.
If I do care, I’ll open the implementation and read the code itself. If it’s a good piece of code its enough to understand. Moving to real world example, LiveData class, I know how the observable pattern works and I know how LiveData works, but and I don’t care how LiveData is implemented.
So yeah, in the end I would like to add “plug&play” functionality.
“Also by having the `val networkUiBehaviourImpl` (why would you name it ...Impl btw?)”
That name is indeed awful, it was a “replace error”. (updated)
“You started with 2 separate interfaces with separate functionality which now intertwined and cannot reuse properly anymore without each other. “
You can use them both or separately, default’s null (no UI interaction will happen). Also, the code is really simple to understand, of course I could have added a small doc explanation (updated), or added a new layer of abstraction by creating a NetworkWithUiBehaviour class without the default.
“I think you should dig into delegation, you can get all the functionality with delegation in a much nicer way. This just feels very wrong an more like abusing than using.”
I do have a branch of this example using delegation. I have a class that implements each interface and in the ViewModel I do something like: NetworkBehaviour by SimpleNetworkBehaviour.
I find it cleaner, sure, I keep the interface without implementation and I allow multiple implementations. But I didn’t solve the field/method visibility problem. Do you have any documentation that you could share the link so I can instruct myself? Also, if you have time and motivation would you help me by pointing where and how should I refactor my example to make it better?
Again, thanks for you comment, regards and happy new year.