/* ****************************************************************** * * Marcos Abreu Bento * * marcosbento@gmail.com * * ------------------------------------------------------------------ * * My implementation of Factory Method design pattern * * ****************************************************************** */ #include #include "Factory.hpp" #include "Product.hpp" #include "BigProduct.hpp" #include "SmallProduct.hpp" int main (void) { typedef Factory GenericFactory; // Simplifying the factory type... GenericFactory factory; // Register products and 'generation' methods... factory.registerProduct("BigProduct", GenericFactory::generate); factory.registerProduct("SmallProduct", GenericFactory::generate); // Calling for product creation // NOTE: The use of auto pointer ensures that newly allocated object // is automatically destroyed as the end of scope std::auto_ptr bp(factory.newProduct("BigProduct")); std::auto_ptr sp(factory.newProduct("SmallProduct")); bp->doFeature(); sp->doFeature(); return 0; }