/** * factorymethod.h * Implemented by Blueprint Technologies, Inc. */ #ifndef _factorymethod_h #define _factorymethod_h /** * Defines the interface of objects the factory method creates. */ class Product { }; /** * Implements the Product interface. */ class ConcreteProduct: public Product { }; /** * Declares the factory method, which returns an object of * type Product. Creator may also define a default implementation * of the factory method that returns a default ConcreteProduct object. */ class Creator { protected: virtual Product* factoryMethod() = 0; public: void anOperation() { Product* product = factoryMethod(); /** * Do some things with the Product object. */ delete product; }; }; /** * Overrides the factory method to return an instance of * a ConcreteProduct object. */ class ConcreteCreator: public Creator { protected: virtual Product* factoryMethod() { return new ConcreteProduct(); }; }; #endif