#include<memory>
#include<iostream>
#include<string>
#include<cctype>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
enum Ctype {coreA,coreB};
class SingleCore{
public:
virtual void print(){
cout << "siglecore_print"<<endl;
}
~SingleCore(){
cout <<"~~singlecore"<<endl;
}
};
class SingleCoreA :public SingleCore{
public:
void print(){
cout << "A_print"<<endl;
}
~SingleCoreA(){
cout <<"~~singlecoreA"<<endl;
}
};
class SingleCoreB :public SingleCore{
public:
void print(){
cout << "B_print"<<endl;
}
~SingleCoreB(){
cout <<"~~singlecoreB"<<endl;
}
};
class DoubleCore{
public:
virtual void print(){
cout << "double_print"<<endl;
}
~DoubleCore(){
cout <<"~~doublecore"<<endl;
}
};
class DoubleCoreA :public DoubleCore{
public:
void print(){
cout << "doubleA_print"<<endl;
}
~DoubleCoreA(){
cout <<"~~doublecoreA"<<endl;
}
};
class DoubleCoreB :public DoubleCore{
public:
void print(){
cout << "doubleB_print"<<endl;
}
~DoubleCoreB(){
cout <<"~~doublecoreB"<<endl;
}
};
class Factory{
public:
virtual SingleCore* creatCore(){}
virtual DoubleCore* creatdouleCore(){}
};
class FactoryA : public Factory{
public:
SingleCoreA* creatCore (){
return new SingleCoreA;
}
DoubleCoreA* creatdouleCore (){
return new DoubleCoreA;
}
};
class FactoryB : public Factory{
public:
SingleCoreB* creatCore (){
return new SingleCoreB;
}
DoubleCoreB* creatdouleCore (){
return new DoubleCoreB;
}
};
int main(int argc, char *argv[])
{
auto_ptr<Factory> faca (new FactoryA() );
auto_ptr<SingleCore> sina (faca->creatCore () );
auto_ptr <DoubleCore> doua (faca->creatdouleCore () );
sina->print ();
doua->print ();
return 0;
}
设计模式_抽象工厂
最新推荐文章于 2024-09-02 18:19:21 发布