classCarBuilder : public Builder { private: Car* car_; public: CarBuilder(): car_(nullptr) { reset(); } voidreset(){ if (car_) delete car_; car_ = newCar(); } voidsetSeats(...){ // set num of seats in the car } voidsetEngine(...){ // set engine type } voidsetTripComputer(...){ // set Trip computer type } voidsetGPS(...){ // install GPS } Car* getProduct(){ Car* car = car_; reset(); return car; } };
classDirector { public: Car* constructSportsCar(Builder& builder){ builder.reset(); builder.setSeats(2); builder.setEngine("someEngine"); builder.setTripComputer(true); builder.setGPS(true); return builder.getProduct(); } Car* constructSUV(Builder& builder){ // steps to build an SUV } };