//other class a car builder that need classCarEngine; classGPS;
//a pure abstract class to use as an interface classCarBuilder { public: virtualvoidreset()= 0; virtualvoidsetSeats(int number)= 0; virtualvoidsetEngine(const CarEngine &engine)= 0; virtualvoidsetGPS(const GPS &gps)= 0; };
classCar; //a car builder that build car itself classCarCarBuilder: public CarBuilder { private: Car *_car; public: virtualvoidreset()override{ if (_car) { delete _car; } _car = newCar(); }
virtualvoidsetSeats(int number)override{ //set seat for car itself }
virtualvoidsetEngine(const CarEngine &engine)override{ //set engine for car itself }
virtualvoidsetGPS(const GPS &gps)override{ //set gps for car itself }
virtual Car* getResult(){ return _car; }; };
classCarManual; //a car builder that build car's manual classCarManualBuilder: public CarBuilder { private: CarManual *_manual;
//a manager class that use builder to build car classCarCarBuilderDirector { public: Car* buildSUV(CarBuilder &builder){ builder.setSeats(4); NormalEngine normalEngine; builder.setEngine(normalEngine); NormalGPS normalGps; builder.setGPS(normalGps); }