PureMVC/puremvc-cpp-multicore-framework

intialize methods are not called from base class contructor (Facade, MacroCommand..)

Opened this issue · 3 comments

In c++ virtual methods defined by the base class called from its constructor won't be correctly resolved to overridden methods defined in the derived class like in Java.

Eg:

class StartupCommand : public Patterns::MacroCommand, virtual public Interfaces::ICommand
{
public:
    // Override
    virtual void initializeMacroCommand() override;
};

void StartupCommand::initializeMacroCommand()
{
    addSubCommand(new PrepViewCommand());
    addSubCommand(new PrepModelCommand());
}

In this case, overridden initializeMacroCommand() will not be called.
This in-constructor behavior might need to be changed to normal methods
that get called on registration or a more proper time.

Hi there,

Do you have suggestions for a fix?

Cheers,
-=Cliff>

One idea for commands might be adding a "virtual void initialize() = 0" in interface class (ICommand), and have derived class implement that (MacroCommand would implement that in place of initializeMacroCommand), and then let that method be called on registration (Controller::registerCommand), provided that command registration only happens once per command.

Would you be willing to implement and test the fix? Command registration should only happen once, BTW.

Cheers,
-=Cliff>