How to easily substitute a Base class

Posted by JTom on Stack Overflow See other posts from Stack Overflow or by JTom
Published on 2010-05-08T15:36:13Z Indexed on 2010/05/08 15:38 UTC
Read the original article Hit count: 284

Hi,

I have the following hierarchy of classes

class classOne
{
    virtual void abstractMethod() = 0;
};

class classTwo : public classOne
{
};

class classThree : public classTwo
{
};  

All classOne, classTwo and classThree are abstract classes, and I have another class that is defining the pure virtual methods

class classNonAbstract : public classThree
{
    void abstractMethod();

    // Couple of new methods
    void doIt();
    void doItToo();
};

And right now I need it differently...I need it like

class classNonAbstractOne : public classOne
{
    void abstractMethod();

    // Couple of new methods
    void doIt();
    void doItToo();
};

class classNonAbstractTwo : public classTwo
{
    void abstractMethod();

    // Couple of new methods
    void doIt();
    void doItToo();
};

and

class classNonAbstractThree : public classThree
{
    void abstractMethod();

    // Couple of new methods
    void doIt();
    void doItToo();
};

But all the nonAbstract classes have the same new methods, with the same code...and I would like to avoid copying all the methods and it's code to every nonAbstract class. How could I accomplish that?

Hopefully it's understandable...

© Stack Overflow or respective owner

Related posts about class

Related posts about object-oriented-design