#ifndef PROTOCOL_H #define PROTOCOL_H /////////////////////////////////////////////////////////////// // protocol.h - define protocol class // // ver 1.1 // // // // this is all the client knows about the protocol, e.g., // // the language // /////////////////////////////////////////////////////////////// // 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 | // +-----------+ +-----------+ +-----------+ // /////////////////////////////////////////////////////////////// // build process // /////////////////////////////////////////////////////////////// // Required files: // // protocol.h, derived1.cpp derived2.cpp // // // // To build in integrated environment: // // - create Win32 Dynamic-Link Library project // // named dynLL // // - protocol.h, derived1.cpp and derived2.cpp // // - build // /////////////////////////////////////////////////////////////// #ifdef IN_DLL #define DLL_DECL __declspec(dllexport) #else #define DLL_DECL __declspec(dllimport) #endif class protocol { public: virtual int getInt() = 0; virtual void putInt(int) = 0; virtual void kill() = 0; static DLL_DECL protocol* make_d1(); static DLL_DECL protocol* make_d2(); }; #endif