2019-10-19 07:52:26 +00:00
|
|
|
|
#include "BuilderPattern.h"
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
2021-10-28 15:15:51 +00:00
|
|
|
|
// 抽象建造者
|
2019-10-19 07:52:26 +00:00
|
|
|
|
AbstractBuilder *builder;
|
2021-10-28 15:15:51 +00:00
|
|
|
|
// 指挥者
|
2019-10-19 07:52:26 +00:00
|
|
|
|
Director *director = new Director();
|
2021-10-28 15:15:51 +00:00
|
|
|
|
// 产品:House
|
2019-10-19 07:52:26 +00:00
|
|
|
|
House *house;
|
|
|
|
|
|
2021-10-28 15:15:51 +00:00
|
|
|
|
// 指定具体建造者A
|
2019-10-19 07:52:26 +00:00
|
|
|
|
builder = new ConcreteBuilderA();
|
|
|
|
|
director->setBuilder(builder);
|
|
|
|
|
house = director->construct();
|
|
|
|
|
house->printfHouseInfo();
|
2020-11-29 07:28:46 +00:00
|
|
|
|
delete builder;
|
2019-10-19 07:52:26 +00:00
|
|
|
|
|
2021-10-28 15:15:51 +00:00
|
|
|
|
// 指定具体建造者A
|
2019-10-19 07:52:26 +00:00
|
|
|
|
builder = new ConcreteBuilderB();
|
|
|
|
|
director->setBuilder(builder);
|
|
|
|
|
house = director->construct();
|
|
|
|
|
house->printfHouseInfo();
|
|
|
|
|
|
|
|
|
|
system("pause");
|
2020-11-29 07:28:46 +00:00
|
|
|
|
|
|
|
|
|
delete director;
|
|
|
|
|
delete builder;
|
|
|
|
|
|
2019-10-19 07:52:26 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|