How to properly extend interface?
c++
Solution
I'll give the benefit of the doubt that you DO indeed need/want multiple inheritance. I see it as good in only limited situations, and interfaces is one of them (even Java allows this).
As said above, use virtual inheritance and be sure to only use pure `virtual` methods in the interface `class`es.
class IDrawable {
public:
virtual ~IDrawable();
virtual void doSomething() = 0;
};
class IExtendedDrawable: virtual public IDrawable {
public:
virtual ~IExtendedDrawable();
virtual void doSomethingElse() = 0;
};
class DrawableImplementation: virtual public IDrawable {
public:
virtual ~DrawableImplementation();
virtual void doSomething() {/*code here*/}
};
class ExtendedDrawableImplementation:
public DrawableImplementation, public IExtendedDrawable
{
public:
virtual ~ExtendedDrawableImplementation();
virtual void doSomething() {/*code here*/}
virtual void doSomethingElse() {/*code here*/}
};
Problem
I have interface based on another: ``` class IDrawable { public: virtual ~IDrawable(); }; class IExtendedDrawable: public IDrawable { public: virtual ~IExtendedDrawable(); }; class DrawableImplementation: public IDrawable { public: virtual ~DrawableImplementation(); }; class ExtendedDrawableImplementation: public DrawableImplementation, public IExtendedDrawable { public: virtual ~ExtendedDrawableImplementation(); }; ``` Then `ExtendedDrawableImplementation` = `DrawableImplementation (+IDrawable)` + `IExtendedDrawable (+IDrawable)` Is it right to have `IDrawable` twice in same class?