装饰模式(学前)

#include<iostream>
#include <string>

using namespace std;
enum eTStyle
{
	T_STYLE1=0,
	T_STYLE2,
	T_STYLE3

};
class CTshirt
{
private:
	string m_scolor;
	int m_nsize;
	eTStyle m_estyle;
public:
	CTshirt(string color, int size, eTStyle style)
	{
		m_scolor = color;
		m_nsize = size;
		m_estyle = style;
	}
	string GetColor()
	{
		return m_scolor;
	}
	int GetSize()
	{
		return m_nsize;
	}
	eTStyle GetStyle()
	{
		return m_estyle;
	}
};
class CPants
{
private:
	string m_scolor;
	int m_nsize;
	eTStyle m_estyle;
public:
	CPants(string color, int size, eTStyle style)
	{
		m_scolor = color;
		m_nsize = size;
		m_estyle = style;
	}
	string GetColor()
	{
		return m_scolor;
	}
	int GetSize()
	{
		return m_nsize;
	}
	eTStyle GetStyle()
	{
		return m_estyle;
	}
};
class CShoes
{
private:
	string m_scolor;
	int m_nsize;
	eTStyle m_estyle;
public:
	CShoes(string color, int size, eTStyle style)
	{
		m_scolor = color;
		m_nsize = size;
		m_estyle = style;
	}
	string GetColor()
	{
		return m_scolor;
	}
	int GetSize()
	{
		return m_nsize;
	}
	eTStyle GetStyle()
	{
		return m_estyle;
	}
};
class CSuits
{
private:
	CTshirt *m_pshirt;
	CPants *m_ppants;
	CShoes *m_pshoes;
public:
	CSuits(CTshirt *pshirt, CPants *ppants, CShoes *pshoes)
	{
		m_pshirt = pshirt;
		m_ppants = ppants;
		m_pshoes = pshoes;
	}
	CTshirt* GetShirt()
	{
		cout << "-------------------Shirt-----------------" << endl;
		cout << "Color is : " << m_pshirt->GetColor() << endl;
		cout << "Size is : " << m_pshirt->GetSize() << endl;
		cout << "Style is: " << m_pshirt->GetStyle() << endl;

		return m_pshirt;
	}
	CPants* GetPants()
	{
		cout << "-------------------Pants-----------------" << endl;
		cout << "Color is : " << m_ppants->GetColor() << endl;
		cout << "Size is : " << m_ppants->GetSize() << endl;
		cout << "Style is: " << m_ppants->GetStyle() << endl;
		return m_ppants;
	}
	CShoes* GetShoes()
	{
		cout << "-------------------Shoes-----------------" << endl;
		cout << "Color is : " << m_pshoes->GetColor() << endl;
		cout << "Size is : " << m_pshoes->GetSize() << endl;
		cout << "Style is: " << m_pshoes->GetStyle() << endl;
		return m_pshoes;
	}
	void GetAll()
	{
		GetShirt();
		GetPants();
		GetShoes();
	}
};
int main()
{
	CTshirt *pshirt = new CTshirt("red", 165, T_STYLE1);
	CPants *ppants = new CPants("white", 165, T_STYLE1);
	CShoes *pshoes = new CShoes("black", 37, T_STYLE1);
	CSuits *psuit = new CSuits(pshirt, ppants, pshoes);
	psuit->GetAll();

	return 0;
}


运行结果
-------------------Shirt-----------------
Color is : red
Size is : 165
Style is: 0
-------------------Pants-----------------
Color is : white
Size is : 165
Style is: 0
-------------------Shoes-----------------
Color is : black
Size is : 37
Style is: 0
请按任意键继续. . .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值