Home:ALL Converter>Virtual multiple interface

Virtual multiple interface

Ask Time:2015-07-01T19:19:38         Author:Madhu Kumar Dadi

Json Formatter

I need help for an implementation that uses multiple inheritance of Interfaces...

There is an existing code whith an interface which has a lot of functions. The instances are created using a factory.

class IBig
{
    // Lot of pure virtual functions
};
And his inplementation:

class CBig: public IBig
{
    // Implementation
}

I Want to split the interface in multiple smaller interfaces, but it should stay compatible to the existing code for some time.

Here is a sample of what I tried to do:

class IBaseA
{
public:
    virtual void DoA() = 0;
};

class IBaseB
{
public:
    virtual void DoB() = 0;
};

// The same interface, now based on multiple smaller interfaces
class IBig : public IBaseA, public IBaseB
{
};

class CBaseA: public IBaseA
{
public:
    virtual void DoA()
    {
        printf("DoA\n");
    }
};

class CBaseB: public IBaseB
{
public:
    virtual void DoB()
    {
        printf("DoB\n");
    }
};

// Inherit from base classes where the implementation is, and from IBig as 
// the instance of CBig is returned as IBig.
class CBig: public CBaseA, public CBaseB, public IBig
{
};

The problem here is that the class CBig cannot be instanciated. The compiler says the functions DoA and DoB are pure virtual, even if they are inplemented in CBaseA and CBaseB. What should I do if i don't want to implement again the functions, just to call the function of the base class ?

NB: I know the design is ugly, but this is only temporary until the big interface can be replaced, and.... I want to understand ! ;-)

Thanks in advance !

Author:Madhu Kumar Dadi,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/31159824/virtual-multiple-interface
yy