Decorator
// Widget.h
#ifndef _WIDGET_H
#define _WIDGET_H
class Widget {
public:
Widget();
virtual void draw() = 0;
};
#endif
說明:
- 設計可『組合』其他同源類別功能之新類別。
- 所有類別均繼承 Widget。
- 創建新類別:Decorator。
- 衍生新可組合功能類別群。
// Decorator.h
#ifndef _DECORATOR_H
#define _DECORATOR_H
#include "Widget.h"
class Decorator : public Widget {
public:
Decorator(const Widget * myWidget);
void draw();
private:
Widget * myWidget;
};
#endif