事实上,CreateUI方法也是在这个文件中实现的。当用户开始交互时,它创建用户接口。mainMenu、所有的子菜单和一切页面都是这个方法产生的,chapter的属性也是其赋予的。
void CreateUI() {
mainMenu = new Menu("main");
// addition
Menu* m = new Menu("+");
mainMenu->addMenuItem(m);
// level-1 page
Page* p = new Page("L1");
p->setChapterProperties(Chapter::NormalChapter, \
ContentFactory::Addition, ContentFactory::Level1Content);
m->addMenuItem(p);
// level-2 page
p = new Page("L2");
p->setChapterProperties(Chapter::NormalChapter, \
ContentFactory::Addition, ContentFactory::Level2Content);
m->addMenuItem(p);
...
我们接着来看这个应用的设计模式。
就像你所想的,MFK_Hardware是Facade模式的一个例子。它将底层的硬件管理问题隐藏起来,并对客户端提供了干净的接口。它同时也是 Singleton模式的代表,因为整个系统运行时其只产生一个实例。为了实现这个功能,MFK_Hardware的构造器、复制和赋值操作都被声明为私有方法。
// File: MFK_Hardware.h
// private constructor to achieve singleton pattern
MFK_Hardware();
MFK_Hardware(MFK_Hardware const&); // copy disabled
void operator=(MFK_Hardware const&); // assigment disabled
你只能通过getInstance静态方法访问它们,这个方法是公共的:
// File: MFK_Hardware.h
// static method to get the instance
static MFK_Hardware* getInstance() {
static MFK_Hardware hw;
return &hw;
};
|