C++???????????????????
???????????? ???????[ 2015/6/1 13:12:44 ] ????????????????
????????????????????????????Щ???????????????????????????????????? ???????????????????????????????????????Щ????????????????????????????????????????????????????????????????????????? ????????????????У????????????????????????????????????????Ρ???????????????ε?????????£????????????????????????
#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;
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11