classrelationships1

本文深入解析了C++中基本协议类及其派生类的使用,阐述了继承与接口在类设计中的作用,同时强调了类成员函数在实现特定功能时的相互依赖关系。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值