????????????????????????????Щ???????????????????????????????????? ???????????????????????????????????????Щ????????????????????????????????????????????????????????????????????????? ????????????????У????????????????????????????????????????Ρ???????????????ε?????????£????????????????????????
#include <iostream>
#include <string>
using namespace std;
class Phone
{
public:
Phone() {}
virtual ~Phone() {}
virtual void ShowDecorate() {}
};
class iPhone:public Phone
{
private:
string m_name;
public:
iPhone(string name):m_name(name){}
~iPhone() {}
void ShowDecorate()
{
cout << m_name << "?????" <<endl;
}
};
class AndroidPhone : public Phone
{
private:
string m_name;
public:
AndroidPhone(string name):m_name(name){}
~AndroidPhone() {}
void ShowDecorate()
{
cout << m_name << "?????" <<endl;
}
};
class DecoratorPhone : public Phone
{
private:
Phone *m_phone;
public:
DecoratorPhone(Phone *phone):m_phone(phone) {}
virtual void ShowDecorate()
{
m_phone->ShowDecorate();
}
};
class DecoratorPhoneA:public DecoratorPhone
{
public:
DecoratorPhoneA(Phone *phone) : DecoratorPhone(phone) {}
void ShowDecorate()
{
DecoratorPhone::ShowDecorate();
AddDecorate();
}
private:
void AddDecorate()
{
cout << "??????" << endl;
}
};
int main()
{
Phone *dpa = new DecoratorPhoneA(new iPhone("5s"));
dpa->ShowDecorate();
delete dpa;
Phone *dpb = new DecoratorPhoneA(new AndroidPhone("Mi2s"));
dpb->ShowDecorate();
system("pause");
return 0;
}