#ifndef PROTOCOL_H #define PROTOCOL_H /////////////////////////////////////////////////////////////////////////// // protocol.hpp - define protocol class // // // // this is all the client knows about the protocol, e.g., the language // // // // Jim Fawcett, CSE791 - Distributed Objects, Demonstration // /////////////////////////////////////////////////////////////////////////// /* design note: ------------ Protocol class hierarchies (sometimes called homeomorphic class structures) consist of an abstract base class and usually a single layer of derived classes. The base class provides a language, or protocol, for client access to all the derived classes. Clients know only the protocol, but not any of the details which distinguish one class from another. The derived classes provide all of the real functionality. The client code, however, does not need to know how any of the derived classes do their business. In this demonstration the member functions getInt() and putInt() are pure virtual functions so protocol class is an abstract base class. No protocol objects can be created. Only objects of derived classes which give definitions for both the pure virtual functions are concrete and can create objects. However, since the make_d1() and make_d2() protocol member functions are static they don't need objects to invoke them. Client code can do that with the syntax protocol::make_d1(), etc. So, we can invoke static members of an abstract class. We do just that in the client code in protocol.cpp +-----------+ | protocol | +-----+-----+ | / \ +--------------+--------------+ | | | +-----+-----+ +-----+-----+ +-----+-----+ | derived1 | | derived2 | | more der | +-----------+ +-----------+ +-----------+ */ typedef std::string stdStr; class protocol { public: virtual int getInt() = 0; virtual void putInt(int) = 0; virtual std::string passVal(std::string s) = 0; virtual std::string passRef(std::string &s) = 0; static protocol* make_d1(); static protocol* make_d2(); }; #endif