/////////////////////////////////////////////////////////////////////////// // client.cpp - demonstrate use of protocol language // // // // this file represents client code, which knows only about the // // protocol class, e.g., the protocol language and the names, but // // not the details, of the derived classes // // // // Jim Fawcett, CSE 791 - Distributed Objects, Demonstration // /////////////////////////////////////////////////////////////////////////// #include #include #include "protocol.h" // note that the client only needs the base class // header file, not headers from derived classes using namespace std; void main() { cout << "\n" << " testing protocol \n" << "==================\n\n"; int i=0; // note that clients can not make a protocol object, but factory functions // make anonymous derived class objects and give client access to them // through a base class protocol pointer. /////////////////////////////////////////////////////////////////////////// // client uses the first derived class, knowing only the protocol // // language and how to call its object factory // /////////////////////////////////////////////////////////////////////////// protocol *bptr = protocol::make_d1(); // factory function creates // derived object bptr->getInt(); // derived class functions bptr->putInt(i); // use base class interface string s = " string from client"; cout << (bptr->passVal(s)).c_str() << endl; cout << (bptr->passRef(s)).c_str() << endl; delete bptr; cout << endl; // /////////////////////////////////////////////////////////////////////////// // client uses the second derived class, knowing only the protocol // // language and how to call its object factory // /////////////////////////////////////////////////////////////////////////// bptr = protocol::make_d2(); // factory function creates // another derived object bptr->getInt(); bptr->putInt(i); s = " string from client"; cout << (bptr->passVal(s)).c_str() << endl; cout << (bptr->passRef(s)).c_str() << endl; delete bptr; cout << endl; }