c++ - Nested interface inheritance implementation -


i encounter scenario of nested interface declarations , implementation, , looking better solution. 2 possible solutions can think of either have wrapper objects in implementation, or using diamond inheritance. not satisfy wrapper objects if have on ten methods in each interface there lot of wrapper methods in each level of implementation class. diamond inheritance implementation more concise told avoid using diamond inheritance whenever possible. can suggest alternative better solution 2 in question?

the wrapper object implementation is

class ia { public:     virtual void ma() = 0; };  class ib : public ia { public:     virtual void mb() = 0; };  class ic : public ib { public:     virtual void mc() = 0; };  class id : public ic { public:     virtual void md() = 0; };  // ------------------------  class impla : public ia { public:     void ma() { /* */ } };  class implb : public ib { public:     void ma() { a.ma(); }     void mb() { /* b */ } private:     impla a; };  class implc : public ic { public:     void ma() { b.ma(); }     void mb() { b.mb(); }     void mc() { /* c */ } private:     implb b; };  class impld : public id { public:     void ma() { c.ma(); }     void mb() { c.mb(); }     void mc() { c.mc(); }     void md() { /* d */ } private:     implc c; }; 

the diamond inheritance examples is

class ia { public:     virtual void ma() = 0; };  class ib : public virtual ia { public:     virtual void mb() = 0; };  class ic : public virtual ib { public:     virtual void mc() = 0; };  class id : public virtual ic { public:     virtual void md() = 0; };  // ------------------------  class impla : public virtual ia { public:     void ma() { /* */ } };  class implb : public ib, public virtual impla { public:     void mb() { /* b */ } };  class implc : public ic, public virtual implb { public:     void mc() { /* c */ } };  class impld : public id, public implc { public:     void md() { /* d */ } }; 

if i'm facing complex design tasks inheritance involved, crtp comes mind. i'm not sure if here. depends bit "meaning" of interfaces, classes, , methods.

which leads me question of "meaning" in relation "design" in general. 2 points important here

  • readability. make simple , clear possible.
  • abstraction. design should reflect model part in real world.

drawing 2 solutions uml (or without that), may see structure similar. implc example has instance of implb member or has parent. boils down question of composition vs inheritance.


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 -