class BasicProtocol /* : possible base classes */ // MessageCreator or MessageHelper.
{
public:
BasicProtocol();
virtual ~BasicProtocol();
bool BasicMsgA( /*...*/ );
bool BasicMsgB( /*...*/ );
bool BasicMsgC( /*...*/ );
};
class Protocol1 : public BasicProtocol // is-a or works-like-a ?
{
public:
Protocol1();
~Protocol1();
bool DoMsg1( /*...*/ );
bool DoMsg2( /*...*/ );
bool DoMsg3( /*...*/ );
bool DoMsg4( /*...*/ );
};
class Protocol2 : public BasicProtocol
{
public:
Protocol2();
~Protocol2();
bool DoMsg1( /*...*/ );
bool DoMsg2( /*...*/ );
bool DoMsg3( /*...*/ );
bool DoMsg4( /*...*/ );
bool DoMsg5( /*...*/ );
};
// Each DoMsg…() member function calls the BasicProtocol::Basic…() functions as needed to perform the common work,
// but the DoMsg…() function performs the actual transmissions itself. Each class may have additional members,
// but you can assume that all significant members are shown.
// 1.BasicProtocol provides no virtual functions (other than the destructor, which we'll get to in a minute).[5]
// This means that it is not intended to be used polymorphically, which is a strong hint against public inheritance.
// 2.BasicProtocol has no protected functions or members. This means that there is no "derivation interface,"
// which is a strong hint against any inheritance at all, either public or private.
// 3.BasicProtocol encapsulates common work, but as described, it does not seem to actually perform its own transmissions as the derived classes do.
// This means that a BasicProtocol object does not WORK-LIKE-A derived protocol object
classrelationships1
最新推荐文章于 2019-02-14 10:00:56 发布