什么是最简单的示例CMakeLists.txt
,main.cpp
以及PureMVC sources
从 execute() Startup SimpleCommand 显示“Hello Startup”?
PureMVC 源代码在这里
理想的解决方案可能是 github 项目的链接。
您应该编译相应的 dll 和 lib(Debug 或 Release [static|shared]),包括 PureMVC 文件。也许你可以从 PureMVC::Patterns::Facade 派生一个外观,覆盖必要的虚函数。因为 C++ 和类 Java 编程语言不同,重写的 initializeController() 不会在基类的构造函数中调用!这是一个派生示例:
class ApplicationFacade
: public virtual IFacade
, public Facade
{
friend class Facade;
public:
static const string STARTUP;
static const string EXIT;
protected:
ApplicationFacade(void)
: Facade(this, "ApplicationFacade")
{
initializeController();
}
public:
static ApplicationFacade& getInstance(void)
{
if (Facade::hasCore("ApplicationFacade"))
return *(dynamic_cast<ApplicationFacade*>(&Facade::getInstance("ApplicationFacade")));
return *(new ApplicationFacade());
}
protected:
virtual void initializeNotifier(string const& key)
{
Facade::initializeNotifier(key);
}
virtual void initializeFacade()
{
Facade::initializeFacade();
}
virtual void initializeController(void)
{
Facade::initializeController();
StartupCommand* startupCommand = new StartupCommand();
registerCommand(STARTUP, startupCommand);
ExitCommand* exitCommand = new ExitCommand();
registerCommand(EXIT, exitCommand);
}
~ApplicationFacade()
{
}
};
const string ApplicationFacade::STARTUP = "startup";
const string ApplicationFacade::EXIT = "exit";
StartupCommand 和 ExitCommand 派生自 PureMVC::Patterns::SimpleCommand 然后在 main.cpp 中您可以通过以下方式启动程序:
ApplicationFacade& facade = ApplicationFacade::getInstance();
facade.sendNotification(ApplicationFacade::STARTUP);
并退出:
facade.sendNotification(ApplicationFacade::EXIT);