/////////////////////////////////////////////////////////////////////// // facade.cpp - implements interface methods // // // // Demonstrates use of a facade class that implements // // an interface's methods, using services of several // // product classes. // // // // Jim Fawcett, CSE687 - Object Oriented Design, Spring 2001 // /////////////////////////////////////////////////////////////////////// // Note: // // Notice that this class does not declare the static factory // // method. This implementation file implements the method // // productAbstraction::createProduct() on behalf of the interface. // /////////////////////////////////////////////////////////////////////// #include #include "facade.h" using namespace std; productAbstraction *productAbstraction::pPA = NULL; //----< void constructor >--------------------------------------------- facade::facade() : _request(), _reply() { cout << "\n constructing facade"; // tell request how to communicate with reply _request.Register(&_reply); } //----< destructor >--------------------------------------------------- facade::~facade() { cout << "\n destroying facade"; } //----< a method solely implemented by facade >------------------------ void facade::hello() { cout << "\n Hello. This is the facade class."; } //----< reply method delegates its action to replyProduct >------------ std::string facade::reply() { return _reply.reply(); } //----< request method delegates its action to requestProduct >-------- void facade::request(const std::string &req) { _request.request(req); } //----< the static factory method that creates everything >------------ // // This is a singleton method. Only one facade object can be created. // productAbstraction* productAbstraction::createProduct() { if(pPA == NULL) { pPA = new facade; return pPA; } return pPA; }