<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          C++核心準(zhǔn)則C.135:使用多重繼承表現(xiàn)多個(gè)不同種類的接口?

          30613d23a429a510070d64e3d0c0cd85.webp

          和田玉

          a9fa3f86d941c91fac98b72a393ae688.webp

          C.135: Use multiple inheritance to represent multiple distinct interfaces

          C.135:使用多重繼承表現(xiàn)多個(gè)不同種類的接口?



          2090e583c89a0534105c65bec1c7629a.webp

          Reason(原因)

          a9fa3f86d941c91fac98b72a393ae688.webp

          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.

          不是所有的類必須支持所有的接口,也不是所有的調(diào)用者都需要所有的操作。最主要的目的是將龐大而僵化的接口分解成被特定派生類支持的行為側(cè)面。



          2090e583c89a0534105c65bec1c7629a.webp

          Example(示例)

          a9fa3f86d941c91fac98b72a393ae688.webp
          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接口的結(jié)合,同時(shí)需要在兩個(gè)獨(dú)立的接口之間進(jìn)行同步。



          2090e583c89a0534105c65bec1c7629a.webp

          Note(注意)

          a9fa3f86d941c91fac98b72a393ae688.webp

          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.

          由于經(jīng)常會(huì)出現(xiàn)一個(gè)實(shí)現(xiàn)需要多個(gè)不同接口的情況,而且這樣的接口通常不容易或者無(wú)法自然地組織成一個(gè)單根繼承,使用多重繼承成為非常普通的做法。



          2090e583c89a0534105c65bec1c7629a.webp

          Note(注意)

          a9fa3f86d941c91fac98b72a393ae688.webp

          Such interfaces are typically abstract classes.

          這樣的接口一般都是抽象類。



          2090e583c89a0534105c65bec1c7629a.webp

          Enforcement(實(shí)施建議)

          a9fa3f86d941c91fac98b72a393ae688.webp


          ???



          2090e583c89a0534105c65bec1c7629a.webp

          原文鏈接:

          a9fa3f86d941c91fac98b72a393ae688.webp

          https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c135-use-multiple-inheritance-to-represent-multiple-distinct-interfaces



          覺得本文有幫助?請(qǐng)分享給更多人。

          關(guān)注【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!

          面向?qū)ο箝_發(fā),面向?qū)ο笏伎迹?/p>

          瀏覽 40
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  大香蕉99热 | 日本色情在线播放 | 久久久亚洲AV无码精品色午夜 | 国产 激情 视频 在线 | 一级毛片毛片毛片 |