java - Should fragment be standalone? -
i'm writing application in android in main activity contains navigation drawer, switches between few different views (displaying data in various ways). each view fragment.
my architecture of choice mvvm - have viewmodels each activity, contain logic of specific view , provide models. views responsible displaying models , handling user interaction.
now, i'm wondering, whether fragments should standalone objects or not? in terms: should serve composite views consisting of visual controls , managed main activity? or should have viewmodels on own , whole logic , main activity should handle showing , hiding them?
pros of fragments being standalone are: better srr (otherwise i'd have implement logic of fragments in main activity's viewmodel), simpler implementation (activity doesn't have pass models each fragment, possibly switch
ing through them check, 1 active) , reusability (i can place fragments next other , work correctly). con didn't see such architecture in examples saw. main activity findviewbyid
s pieces of fragments , put data there.
what common solution such problem?
a fragment should have own , whole logic , totally activity independant can reuse them in other activities.
if want fragment communicate parent activity, called container, can use interface.
tell me if need sample code or if looking informations :)
Comments
Post a Comment