#include #include //for std::vector #include //for std::string using namespace std; class Product{ vector parts; public: void Add(string part){ parts.push_back(part); } void Display(){ cout<<"\nProduct Parts -------"<Add("PartA "); } void BuildPartB(){ product->Add("PartB "); } Product *GetResult(){ return product; } }; class Builder2:public AbstractBuilder{ public: void BuildPartA(){ product->Add("PartX "); } void BuildPartB(){ product->Add("PartY "); } Product *GetResult(){ return product; } }; class Director{ //Builder uses a complex series of steps public: void Construct(AbstractBuilder& builder){ builder.BuildPartA(); builder.BuildPartB(); builder.BuildPartB(); } }; int main(){ // Create one director and two builders Director director; Builder1 b1; Builder2 b2; // Construct two products director.Construct(b1); Product *p1 = b1.GetResult(); p1->Display(); delete p1; director.Construct(b2); Product *p2 = b2.GetResult(); p2->Display(); delete p2; }