android - Adding functionality to the activity (inheritance, decoration, strategy ... ) -


i cannot decide approach should use in next situtation.

one activity app need have different functionality, here leak of multiple inheritence comes play.

what need ?

there several parts activity has have.

  1. navigation drawer. using materialdrawer library. requires activity implement on click callbacks (or use composition instead), use activity constructor argument,so think better put separate class inherited activity or base class provided android framework . library developer doesn't require stuff done in on create method ( setcontentlayout instance)

  2. my activity(one of several) have toolbar , framelayout holding fragment . or better separate toolbar , single fragment ? in turn requires stuff done in oncreate : setcontentlayout basic layout , add fragment container set activity actionbar .....

  3. maybe in future use libraries requires add in activity lifecycle methods.

all these points in order follow single responsibility principle have separate classes inherited base activity.
example have this.

public class singlefragmentactivity<t extends fragment> extends appcompatactivity {  } public class singlefragmenttoolbaractivity<t extends fragment> extends appcompatactivity {  } public class navigationdraweractivity extends appcompatactivity  {  } .... 

as can see each functionality put separate class, if need have singleframgentactivity navigationdrawer ?
in case have inherit 1 of these classes another, example

public class navigationdrawer extends singlefragmentactivity {  } 

if so, have no ability use navigation drawer separately singlefragmentactivity.

what best practice follow in case, how build class hierarchy make flexible , use open-close principle, make changes in application without pain. (use strategy, decorator ..... ?)

i grateful help.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -