If you see "methodParent()", I need to implement it in all the child
classes and is lots of repetition of the code (as well as maintenance
hurdle) for me.
Then implement an Abstract class instead of your interface. Basically it's an interface (containing pure virtual methods that will need to be implemented in childrens) but also containing some "non-pure" (already implemented) virtual methods, that can be overriden later if needed.
In general an abstract class is used to define an implementation and
is intended to be inherited from by concrete classes.
More here
I would do this:
// abstract
class AParent() //Abstract class
{
public:
virtual void methodParent() { ... }; // give a first implementation that can be overriden later on, only if needed
virtual void methodeChild() = 0
};
//Now the concretes
class Child1() : public AParent
{
public:
virtual void methodParent() { ... }; // Override (as an example, only if needed)
virtual void methodChild() { ... }; //implement
};
class InterfaceChild() : public AParent
{
public:
//void methodParent() // is inherited from AParent
virtual void methodChild() { ... }; // implement
};
EDIT If you can't change anything go for this:
But... It's ugly :)
//Interfaces
//=======================================================
class InterfaceParent() //Interface class
{
public:
virtual void methodParent() = 0;
};
class InterfaceChild1() : public InterfaceParent //Interface class
{
public:
virtual void methodParent() = 0;
virtual void methodChild1() = 0;
};
class InterfaceChild2() : public InterfaceParent //Interface class
{
public:
virtual void methodParent() = 0;
virtual void methodChild2() = 0;
};
//Abstract
//=======================================================
//an abstract class to do the transition betwin interfacesChildXX and concrete classes
class AChildXX() : public InterfaceChildXX // Concrete Class
{
public:
virtual void methodParent() { cout << "PARENT_METHOD"; } //It's implemented here for all your childrens, but can still be overriden
virtual void methodChildXX() = 0;
};
// Concrete Classes
//=========================================================
class Child1() : public AChildXX // Concrete Class
{
public:
//void methodParent() { cout << "PARENT_METHOD"; } //It's inherited
void methodChild1() { cout << "CHILD_1_METHOD"; }
};
class Child2() : public AChildXX // Concrete Class
{
public:
// void methodParent() { cout << "PARENT_METHOD"; } //It's inherited
void methodChild2() { cout << "CHILD_2_METHOD"; }
};