阅读下列说明和C++代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 生成器(Builder)模式的意图是将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。图5-1所示为其类图。 【C++代码】 #include<iostream> #include<string> usingnamespacestd; classProduct{ private:??? stringpartA,partB; public: Product(){??} ???void setPartA(conststring&s){PartA=s;} ????void setPartB(conststring&s){PartB=s;} //?其余代码省略 }; classBuilder{ public: ???????(1)??; virtualvoidbuildPartB()=0; ???????(2)??; }; classConcreteBuilder1:publicBuilder{ private: Product*??product; public: ConcreteBuilder1(){product=newProduct();????} ???void buildPartA(){?????(3)????("ComponentA");} ???void buildPartB(){?????(4)????("ComponentB");} Product*getResult(){returnproduct;} //?其余代码省略 }; classConcreteBuilder2:publicBuilder{??? /*???代码省略???*/ }; classDirector{ private:? Builder*builder; public:?? Director(Builder*pBuilder){builder=pBuilder;} ????void construct(){ ???????(5)????;??? //?其余代码省略 ?????} //?其余代码省略 }; intmain(){ Director*director1=newDirector(newConcreteBuilder1());? director1->construct();?? deletedirector1;??? return0;
(1) virtual void buildPartA() = 0 (2) virtual Product * getResult() = 0 (3) product->setPartA (4) product->setPartB (5) builder->buildPartA(); builder->buildPartB(); Product* p = builder->getResult();