???????????C++???
???????????? ???????[ 2014/8/29 14:20:11 ] ??????????????? ???????
????????????
???????????Σ????????????????????????????????????????е??????????????????????????????????????????????????????????????????
???????磬??????????л?????????????????????????????????????????
????UML????£?
????????????????????????????????????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????е??????? ????????ó???????????????????????
????1)?????ж??????壬???????????????????????????
????2)???????????????????????á?
????????????????????????????????????
????1)????????????????????????????????????ó???????????幤??????????????????????е????
????2)???幤????????????к???????????й?????????ó??????????????????????????
????3)??????????????????????е????????????????
????4)??????????????幤????????????????????????????
???????????
#include <iostream>
usingnamespace std;
enum SOAPTYPE {SFJ??XSL??NAS};
enum TOOTHTYPE {HR??ZH};
class SoapBase
{
public:
virtual ~SoapBase(){};
virtualvoid show() = 0;
};
class SFJSoap:public SoapBase
{
public:
void show() {cout<<"SFJ Soap!"<<endl;}
};
class NASSoap:public SoapBase
{
public:
void show() {cout<<"NAS Soap!"<<endl;}
};
class ToothBase
{
public:
virtual ~ToothBase(){};
virtualvoid show() = 0;
};
class HRTooth:public ToothBase
{
public:
void show() {cout<<"Hei ren Toothpaste!"<<endl;}
};
class ChinaTooth:public ToothBase
{
public:
void show() {cout<<"China Toothpaste!"<<endl;}
};
class FactoryBase
{
public:
virtual SoapBase * creatSoap() = 0;
virtual ToothBase * creatToothpaste() = 0;
};
class FactoryA
{
public:
SoapBase * creatSoap()
{
returnnew SFJSoap();
}
ToothBase * creatToothpaste()
{
returnnew HRTooth();
}
};
class FactoryB
{
public:
SoapBase * creatSoap()
{
returnnew NASSoap();
}
ToothBase * creatToothpaste()
{
returnnew ChinaTooth();
}
};
int main()
{
FactoryA factory1;
FactoryB factory2;
SoapBase *pSoap1 = NULL;
ToothBase *pToothpaste1 = NULL;
pSoap1 = factory1.creatSoap();
pToothpaste1 = factory1.creatToothpaste();
pSoap1->show();
pToothpaste1->show();
SoapBase *pSoap2 = NULL;
ToothBase *pToothpaste2 = NULL;
pSoap2 = factory2.creatSoap();
pToothpaste2 = factory2.creatToothpaste();
pSoap2->show();
pToothpaste2->show();
delete pSoap1;
delete pSoap2;
delete pToothpaste1;
delete pToothpaste2;
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