java - Acitivity double inheritence - horrible code -


i have tried solve problem, have no idea how this.
problem activity, working activity not abstract, need inherit properties other classes ,but problem java doesn't support multiple inheritance, there can serial chain.

here class hierarchy.

first class holding fragment (only 1 fragment) , toolbar, bad practice have class multiple responsibilities (solid), have no idea how solve problem. better separate singlefragment , toolbaractivity lead same problem want solve.

public abstract class singlefragmenttoolbaractivity<t extends fragment> extends appcompatactivity implements scrollabletoolbarfragment.toolbarprovider {     protected toolbar mtoolbar;     private float mdisplaydpheight;     private float mdisplaydpwidth;     protected abstract t createfragment();     protected abstract int getfragmentcontainerid();     protected abstract int getlayoutid();    // protected abstract int getactivitytag();     protected abstract int gettoolbarid();     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(getlayoutid());         mtoolbar = (toolbar) findviewbyid(gettoolbarid());         mtoolbar = setuptoolbar(mtoolbar);         // todo fix style or theme !! temporary solution         mtoolbar.settitletextcolor(getresources().getcolor(r.color.white));         setsupportactionbar(mtoolbar);         fragmentmanager fragmentmanager = getsupportfragmentmanager();         fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction();         int fragmentcontainerid = getfragmentcontainerid();         fragment fragment = fragmentmanager.findfragmentbyid(fragmentcontainerid);         if (fragment==null) {             fragment = createfragment();             fragmenttransaction                     .add(fragmentcontainerid,fragment)                     .commit();         }      } 

this not full class declaration, important part.(setting content layout)

this class looks quite normally, if not take account multiple responsibility.

second class responsible implementing navigationdrawer, in case using materialdrawer library here. great library, author has used inversionofcontrol add navigation drawer activity in runtime. doesn't in case.

public abstract class navigationdraweractivity<t extends fragment> extends singlefragmenttoolbaractivity<t> {     private float mdisplaydpwidth;     private float mdisplaydpheight;     private drawer.result mnavigationdrawer;     private accountheader.result maccountheader;     private double mdrawerwidthfactor = 0.9;     private double mdrawerheaderheightfactor = 0.3;     private iprofile<profiledraweritem> mprofile;     profilesettingdraweritem settingdraweritem;     public drawer.result getnavigationdrawer() {         return this.mnavigationdrawer;     }     private accountheader.result geaccountheader() {         return this.maccountheader;     }     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setupnavigationdrawer(savedinstancestate);     } private void setupnavigationdrawer(bundle savedinstancestate) {         getdisplaymetrics();         maccountheader = new accountheader()                 .withactivity(this)        //.....         drawer builddrawer =  new drawer(this)                 .withactivity(this);         .......        } 

for me looks horrible, class derived singlefragmenttoolbaractivity. , when have inherit navigationdraweractivity need declare class

public class testactivity extends navigationdraweractivity<scrollabletestfragment> { 

i know line of code mean.but if developer @ code confused, why need generalize navigationdraweractivity fragment class ?

i have tried apply several patterns here, nothing works should.

decorator - decorating activity can quite difficult wrap activity methods, far activity kind of god object. , delegating methods internally stored (as class member) wrapped activity can painful , not choice @ all.

strategy - use interfaces class members not because these features (single framgent, navigtation drawer...) tightly coupled activity base class , mind cannot suit in situation.

please solve problem, have not enough experience this, ask question here.

thank in advance.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -