///////////////////////////////////////////////////////////////////// // client.cpp - uses protocol defined by interface.h to // // ver 1.0 make request of component // // // // Language: Visual C++, version 6.0, sp5 // // Platform: Dell Dimension 8100, Windows 2000 sp2 // // Application: CSE791 - Distributed Objects // // Demonstration of Programming to Interface // // Author: Jim Fawcett, CST 2-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////////// /* Client Operations: ================== This client uses the announce interface to interact with two of classes derived from the interface and implementing its virtual function, announcer(). Each of these classes simply announces itself and displays its version number. */ // ///////////////////////////////////////////////////////////////////// // component build process // ///////////////////////////////////////////////////////////////////// // Required Files: // // - creatable.h, interface.h, component.h, component.cpp // // // // To Build component dll: // // - create Win32 Dynamic-Link Library project // // - add all the files cited above to the project // // - click on Project\Settings\C/C++ and select Code Generation // // in the Category comboBox. Select component project in tree // // view and select Debug Multithreaded DLL in the list view. // // in the use run-time library comboBox. // // - click on Build\build component.dll // // - copy component.dll and component.lib into client\debug // // you need to do this every time you rebuild the component // // // // To Build client.exe: // // - create Win32 console application // // - add client.cpp and component.lib to the project // // - click on Project\Settings\C/C++ and select Code Generation // // in the Category comboBox. Select client project in tree // // view and select Debug Multithreaded DLL in the list view. // // in the use run-time library comboBox. // // - click on Build\build client.exe // // - click on Build\Execute client.exe // // // // Note: // // This project uses no multithreaded processing. However, when // // building a dll it is essential that you use the dll form of // // the C and C++ libraries for both client and dll, and selecting // // Debug Multithreaded dll causes that to happen. If you forget // // this step, certain uses of the dynamic memory manager will // // cause a process crash. // // // ///////////////////////////////////////////////////////////////////// /* Maintenance History =================== ver 1.0 : 14 Jan 2002 - first release */ // #pragma warning(disable : 4786) #include #include "interface.h" // include component interface ///////////////////////////////////////////////////////////////////// // Note that client does not include any implementation headers. // It includes just the interface header, which contains no // implementation details beyond the factory. // void main() { std::cout << "\n Demonstate Programming to Interfaces " << "\n ======================================\n"; ////////////////////////////////////////////////////////////////// // use interface static members to register its objects with // the static factory. announce::registerObjects(); ///////////////////////////////////////////////////////////////// // client needs to know how to access the ids of the implementation // classes it uses, but does not need to bind to the class names. announce *pAnnounce1 = announce::makeObj(announce::type(1)); if(pAnnounce1 != NULL) { pAnnounce1->setString("first string set by client"); pAnnounce1->announcer(); // polymorphic call delete pAnnounce1; } else std::cout << "\n create announce1 failed\n"; std::cout << std::endl; announce *pAnnounce2 = announce::makeObj(announce::type(2)); if(pAnnounce2 != NULL) { pAnnounce2->setString("second string set by client"); pAnnounce2->announcer(); // polymorphic call delete pAnnounce2; } else std::cout << "\n create announce2 failed\n"; std::cout << std::endl; std::cout << "\n The announceFactory delivers, via announce pointers," << "\n objects that derive from announce. announce interface" << "\n provides a protocol for clients of all derived class" << "\n objects, like test1 and test2, to use, without needing" << "\n to know the derived class of the object they are using."; std::cout << "\n\n"; }