https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
s

stantronic

09/09/2020, 10:43 AM
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

MiSikora

09/09/2020, 11:29 AM
How do you want to do that? Are you on min SDK 28 to leverage AppComponentFactory?
s

stantronic

09/09/2020, 12:57 PM
ooh that looks interesting. Unfortunately we have min sdk 21.
m

MiSikora

09/09/2020, 12:58 PM
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

stantronic

09/09/2020, 12:59 PM
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

MiSikora

09/09/2020, 1:00 PM
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

stantronic

09/09/2020, 1:02 PM
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
2 Views