关键点:Decorator类同被装饰类继承于同一基类
class VisualComponent
{
virutal void Draw();
};
class CDecorator : public VisualComponent
{
public:
CDecorator(VisualComponent* cmp): m_pComponent(cmp){}
void Draw(){
DrawOtherThings();
m_pComponent->Draw();
}
void DrawOtherThings(){}
private:
VisualComponent* m_pComponent;
};
class CTextView : public VisualComponent
{
void Draw(){}
};
void DrawWindow( VisualComponent* pCmp)
{
pCmp->Draw()
}
void main()
{
CTextView* pView = new CTextView ;
DrawWindow( new CDecorator (pVIew) );
}