///////////////////////////////////////////////////////////////////////// // Client.cpp - uses concrete factory and product through abstractions // // // // Jim Fawcett, CSE776 - Design Patterns, Summer 2009 // ///////////////////////////////////////////////////////////////////////// /* * Notes: * - If you examine FactoryMethod.h and ConfigureClient.h you will see that * the client has no binding to either concrete product or concrete factory. * - If we need to substitute a different concrete product subclass, we must * rebuild the ConfigureClient module but do not need to rebuild the client. * - The client can use an open-ended number of concrete products since we * provided the Configure::doConfigure(ProductIndex) with a parameter. */ #include "ConfigureClient.h" #include "Application.h" #include void main() { std::cout << "\n Demonstrating Document-Based Application"; std::cout << "\n ==========================================\n"; int DocIndex = 0; Configure conf; std::cout << "\n configuring client with document index = " << DocIndex; IApplication* pApp = conf.doConfigure(DocIndex); if(pApp) { std::cout << "\n accessing document operation through factory method"; pApp->DoEdit(); } else std::cout << "\n no definition for document with index = " << DocIndex; std::cout << "\n"; delete pApp; DocIndex = 1; std::cout << "\n configuring client with document index = " << DocIndex; pApp = conf.doConfigure(DocIndex); if(pApp) { std::cout << "\n accessing document operation through factory method"; pApp->DoEdit(); } else std::cout << "\n no definition for creator with index = " << DocIndex; std::cout << "\n"; delete pApp; std::cout << "\n client can also access the document through document interface:"; DocIndex = 0; pApp = conf.doConfigure(DocIndex); IDocument* pDoc = pApp->CreateDocument(); pDoc->Edit(); std::cout << "\n\n"; delete pDoc; delete pApp; }