标签:style blog http color strong os
定义
Class EventHandler {
public:
EventHandler(EventHandler* eh) : m_handler(eh) { }
virtual void handle(Event* e) { if (m_handler) m_handler->handle(e); }
private:
EventHandler* m_handler;
}
class Application : EventHandler {
public:
Applicatoin();
void exec() { ... }
}
class Widget : EventHandler {
public:
Widget(Widget* parent) : EventHandler(parent) { }
void draw() { ... }
}
class Window : public Widget {
public:
virtual void handle(Event* e) {
if(e->type() ==
WheelEvent)...;
else
Widget::Handle(e);
}
}
class Button : public Widget{
public:
virutal void handle(Event* e) {
if(e->type == MousePressEvent)
...
else
Widget::handle(e);
}
}
int main()
{
Application app;
Widget widget;
Button button(widget);
return app.exe();
}
Chain of Responsibility - 职责链模式,布布扣,bubuko.com
Chain of Responsibility - 职责链模式
标签:style blog http color strong os
原文地址:http://blog.csdn.net/harrising/article/details/37671707