Hallo guys, wondering about the pros and cons of d...
# android-architecture
s
Hallo guys, wondering about the pros and cons of doing the following:
Copy code
class Activity(val delegate = ScreenDelegate()): AppCompatActivity(), Screen by delegate {
...methods
}
the idea is to create a delegate that activities and fragments can use that encapsulates some general screen behaviour.
m
How do you want to do that? Are you on min SDK 28 to leverage AppComponentFactory?
s
ooh that looks interesting. Unfortunately we have min sdk 21.
m
Then you can’t create activities like this
For fragments you can install a factory on fragment manager if I recall correctly
Unless you meant that it is always a default parameter and you don’t supply different arg at runtime
s
yes - its a default param, as I know the OS requires no-arg constructors
i just wanted a reference to the delegate within the class
m
Yup, in that case it should work but only for those. As for validity of this I think it’s ok. Depends on what the delegate is about
Generally I’d be careful because most likely it should be responsibility of some other class like presenter or w/e
s
there are two main things the delegate will do - one is updating the analytics screen name and the other is managing the composite rx disposable