多个种类接口(接口多个面向对象种类创作者)「实现多个接口」

C.135: Use multiple inheritance to represent multiple distinct interfacesC.135:使用多重继承表现多个不同种类的接口Reason(原因)Not all classes will necessarily support all interfaces, and not all callers will necessarily want to deal with all operations. Especially to break apart monolithic interfaces into "aspects" of behavior supported by a given derived class.不是所有的类必须支持所有的接口,也不是所有的调用者都需要所有的操作
最主要的目的是将庞大而僵化的接口分解成被特定派生类支持的行为侧面
Example(示例)class iostream : public istream, public ostream {   // very simplified    // ...};istream provides the interface to input operations; ostream provides the interface to output operations. iostream provides the union of the istream and ostream interfaces and the synchronization needed to allow both on a single stream.istream提供面向输入操作的接口;ostream提供了面向输出操作的接口
iostream提供了istream和ostream接口的结合,同时需要在两个独立的接口之间进行同步
Note(注意)This is a very common use of inheritance because the need for multiple different interfaces to an implementation is common and such interfaces are often not easily or naturally organized into a single-rooted hierarchy.由于经常会出现一个实现需要多个不同接口的情况,而且这样的接口通常不容易或者无法自然地组织成一个单根继承,使用多重继承成为非常普通的做法
Note(注意)Such interfaces are typically abstract classes.这样的接口一般都是抽象类
Enforcement(实施建议)???原文链接:​https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c135-use-multiple-inheritance-to-represent-multiple-distinct-interfaces觉得本文有帮助?请分享给更多人
更多精彩文章欢迎关注【面向对象思考】
面向对象开发,面向对象思考
多个种类接口(接口多个面向对象种类创作者)
(图片来源网络,侵删)

联系我们

在线咨询:点击这里给我发消息