User:Mydreamzz

'''Adapter and Factory patters working togather:

Problem space:''' A book store needs to provide book related information to its customers. The store deals with books published by a large number of publishers, and would like to provide complete information about books (even those which are not in stock). The customer can search for books by author or title, and provide publisher information he/she has it. The customer can see a complete description of the book, buy it (if available), or place an order for the book (if not available). To be able to provide this kind of information, the store uses a variety of sources for the information. The database in the store has a complete description of all the books stocked in the store, and is the first place to look up any book. When the book is not in stock, the store keeper has to look up catalogs provided by the publishers. Most publishers provide complete online catalogs that can be accessed over internet. The store owner now maintains a list of URLs which provide the calalog services. There is one entry for each publisher in the list. The entry notes the name of the publisher, and the URLs for the catalog home page and search pages.

Solution Space:
 * 1) include
 * 2) include

using namespace std;

/* LocalCatalogAdaptee is the one which does the job of searching the local Catalog */ class LocalCatalogAdaptee {	public: bool searchLocalCatalog(string s){cout<<"I am in LocalCatalog Adaptee searching ..."<<s<<endl;return true;} private:

}; /* URLCatalogAdaptee is the one which does the job of searching the URL  Catalog */ class URLCatalogAdaptee {	public: public: bool searchURL(string s){cout<<"I am in URLCatalogAdaptee searching ..."<<s<<endl;return true;} private: };

class Catalog {	public: static Catalog *getMeCatFactory(int x); virtual bool querySource(string); void whoami{} }; bool Catalog::querySource(string) {	return false; } class LocalDBCatalogAdapter:public Catalog,private LocalCatalogAdaptee {	public: bool querySource(string s); void whoami{cout<<"I am LocalDBCatalog"<<endl;} };

bool LocalDBCatalogAdapter::querySource(string s) { return searchLocalCatalog(s); }

class URLDBCatalogAdapter:public Catalog,private URLCatalogAdaptee {	public: void whoami{cout<<"I am URLDBCatalog"<querySource("MyGoodBook"); Catalog *myFact2 = Catalog::getMeCatFactory(2); myFact2->querySource("TheWildNewBook"); return 1; }