设计模型

<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style=""><span style="font-size: small;">今天终于可以开始学习设计模型了,虽然之前陆陆续续接触到一些模型,但是作为一个学计算机的人必备课程一直拖到现在才开始系统的学习,真是惭愧啊。但愿亡羊补牢,为时未晚吧。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;">Iterator Pattern</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Times New Roman;">1</span></span><span style="">,书架类必须实现</span><span lang="EN-US"><span style="font-family: Times New Roman;">aggregate</span></span><span style="">,改接口必须有一个返回</span><span lang="EN-US"><span style="font-family: Times New Roman;">Iterator</span></span><span style="">的方法。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Times New Roman;">2</span></span><span style="">,优点:实现遍历与实现的分离,实现在</span><span lang="EN-US"><span style="font-family: Times New Roman;">bookshelf</span></span><span style="">中,遍历放在</span><span lang="EN-US"><span style="font-family: Times New Roman;">bookshelf</span></span><span style="">自己特有的</span><span lang="EN-US"><span style="font-family: Times New Roman;">BookShelfIter</span></span><span style="">(实现了</span><span lang="EN-US"><span style="font-family: Times New Roman;">Iterator</span></span><span style="">)中。</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;">Adapter Pattern</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Times New Roman;">1</span></span><span style="">,</span><span lang="EN-US"><span style="font-family: Times New Roman;">Adapter Pattern</span></span><span style="">分为两种:类的</span><span lang="EN-US"><span style="font-family: Times New Roman;">Adapter</span></span><span style="">。要由继承机制来实现。对象的</span><span lang="EN-US"><span style="font-family: Times New Roman;">Adapter</span></span><span style="">,由委托机制来实现。</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Times New Roman;">2</span></span><span style="">,类的</span><span lang="EN-US"><span style="font-family: Times New Roman;">Adapter</span></span><span style="">,场景:固有的类(</span><span lang="EN-US"><span style="font-family: Times New Roman;">PreexistedClass</span></span><span style="">),实现了一些功能,比如可以提供</span><span lang="EN-US"><span style="font-family: Times New Roman;">220</span></span><span style="">伏的电压,可以打印以“</span><span lang="EN-US"><span style="font-family: Times New Roman;">***</span></span><span style="">”开头的字符串。虽然固有的类实现了需要的大部分功能,但是有一些细节并不能够完全符合需要,实际符合需要的接口,</span><span lang="EN-US"><span style="font-family: Times New Roman;">NeedPerformanceInterface</span></span><span style="">,这个接口提供了实际需要的规范(在细节上符合实际需要),比如需要</span><span lang="EN-US"><span style="font-family: Times New Roman;">222</span></span><span style="">伏电压,打印以“</span><span lang="EN-US"><span style="font-family: Times New Roman;">***</span></span><span style="">”开头以“</span><span lang="EN-US"><span style="font-family: Times New Roman;">&amp;&amp;&amp;</span></span><span style="">”结尾的字符串。此时便需要一个</span><span lang="EN-US"><span style="font-family: Times New Roman;">Adapter</span></span><span style="">进行转换,该</span><span lang="EN-US"><span style="font-family: Times New Roman;">Adapter</span></span><span style="">继承了</span><span lang="EN-US"><span style="font-family: Times New Roman;">PreexistedClass</span></span><span style="">(以便调用</span><span lang="EN-US"><span style="font-family: Times New Roman;">PreexistedClass</span></span><span style="">中的方法),同时实现了</span><span lang="EN-US"><span style="font-family: Times New Roman;">NeedPerformanceInterface</span></span><span style="">(以便提供需要的行为)。</span></span></p>

你可能感兴趣的:(设计)