I have a simple class hierarchy of two classes. Both classes call an init-method specific to that class. Therefor the init-method is overriden in the subclass:
class A
{
    public A() { this->InitHandlers(); }
    public virtual void InitHandlers() { // load some event handlers here }
}
class B: public A
{
    public B() { this->InitHandlers(); }
    public virtual void InitHandlers() {
        // keep base class functionality
        A::InitHandlers();
        // load some other event handlers here 
        // ...
    }
}
I know this is evil design:
- The call of an overriden method from constructor is error-prone.
- B::InitHandlers()would be called twice with this setup.
But semantically it makes sense to me: I want to extend the behaviour of class A in class B by loading more handlers but still keeping the handlers loaded by class A. Further this is a task that has to be done in construction. So how can this be solved with a more robust design?
 
     
    