#include
using namespace std;
{
public:
virtual void prepareMonitor()=0;
virtual void prepareCpu()=0;
virtual void prepareDisk()=0;
PCBuilder *GetProduct(){return product;}
private:
PCBuilder *product;
};
{
public:
void prepareMonitor()
{cout<<"cheap"<<endl;}
void prepareCpu()
{}
void prepareDisk()
{}
};
{
public:
void prepareMonitor()
{cout<<"Dear"<<endl;}
void prepareCpu()
{}
void prepareDisk()
{}
};
{
public:
void construct(PCBuilder* builder)
{
builder->prepareMonitor(); //一般来说,客户程序员可以在此处传入参数,本程序省略。
builder->prepareCpu();
builder->prepareDisk();
}
};
void main()
{
Director* dir;
PCBuilder* pd=new DearPCBuilder();
dir->construct(pd);
}
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:[转]C++设计模式:Builder模式 - Python技术站