装饰模式实现服装搭配
来源:互联网 发布:Json 大括号 编辑:程序博客网 时间:2024/04/27 15:38
#include <iostream>using namespace std;class CPerson{private:string m_sname;public:void SetName(string name){m_sname = name;}~CPerson(){}virtual void ShowAll(){cout << "Person ShowAll" << endl;}};class CDress:public CPerson{protected:CPerson *t_component;public:void Decorate(CPerson *component){t_component = component;cout << "t_component:" << t_component << endl;}void ShowAll(){cout << "t_component:"<<t_component << endl;cout << "Dress ShowAll" << endl;//need to just NULLt_component->ShowAll();}};class CShirts :public CDress{public:void ShowAll(){cout << "CShirts this:" << this << endl;cout << "Shirts!" << endl;CDress::ShowAll();}};class CPants :public CDress{public:void ShowAll(){cout << "this:"<<this << endl;cout << "Pants!" << endl;CDress::ShowAll();}};class CShoes :public CDress{public:void ShowAll(){cout <<"CShoes this:"<< this << endl;cout << "Shoes!" << endl;CDress::ShowAll();}};class CCoats :public CDress{public:void ShowAll(){cout << "CCoats this:" << this << endl;cout << "Coats!" << endl;CDress::ShowAll();}};int main(){CPerson *pMM = new CPerson;pMM->SetName("Han Meimei");CPants *ppant = new CPants;CShoes *pshoes = new CShoes;CShirts *pshirts = new CShirts;ppant->Decorate(pMM);pshoes->Decorate(ppant);pshirts->Decorate(pshoes);pshirts->ShowAll();return 0;}
执行结果:
t_component:011A5598
t_component:011AEF90
t_component:011AF738
CShirts this:011AF698
Shirts!
t_component:011AF738
Dress ShowAll
CShoes this:011AF738
Shoes!
t_component:011AEF90
Dress ShowAll
this:011AEF90
Pants!
t_component:011A5598
Dress ShowAll
Person ShowAll
请按任意键继续. . .
注意Decorate(CPerson *componet)。
阅读全文
0 0
- 装饰模式实现服装搭配
- 装饰模式实现穿衣搭配 C++
- 服装搭配
- 穿衣的搭配--装饰模式
- 服装的颜色搭配
- 服装的颜色搭配
- 男士 夏季服装搭配
- 服装搭配技巧
- 服装搭配展示JS特效
- 装饰模式C++实现
- 装饰模式c++实现
- 装饰模式 C++实现
- 装饰模式C++实现
- 装饰模式lua实现
- 装饰模式----C++实现
- 装饰模式--lua实现
- PHP实现装饰模式
- 装饰模式C++实现
- 23:二维数组回形遍历
- 1055. 集体照 (25)
- Zookeeper最常用的作用,作为dubbo的注册中心
- 事件驱动模型和观察者模式
- 实验二 线性表的综合实验(c++)
- 装饰模式实现服装搭配
- Codeforces Round #439 (Div. 2) A. The Artful Expedient
- 20171008Elasticsearch简介
- Java中文件流的关闭问题
- Android_网络请求数据之HttpClient方式(核心代码)
- Python机器学习代码中的命名
- 10.7 剪草 2394
- 58. Length of Last Word(第五周)
- NKOJ 2644 (SCOI 2010) 传送带(三分)