??xml version="1.0" encoding="utf-8" standalone="yes"?>国产真实乱对白精彩久久,国产蜜臀av在线一区二区三区,综合激情一区http://www.aygfsteel.com/sailor/category/33145.html在一|情q日子里,谁能说得清是苦是甜,只知道确定了׃无反?/description>zh-cnSat, 26 Jul 2008 08:19:34 GMTSat, 26 Jul 2008 08:19:34 GMT60模式Q九Q:模板ҎQTemplate MethodQ模?/title><link>http://www.aygfsteel.com/sailor/articles/217607.html</link><dc:creator>sailor</dc:creator><author>sailor</author><pubDate>Sat, 26 Jul 2008 00:25:00 GMT</pubDate><guid>http://www.aygfsteel.com/sailor/articles/217607.html</guid><wfw:comment>http://www.aygfsteel.com/sailor/comments/217607.html</wfw:comment><comments>http://www.aygfsteel.com/sailor/articles/217607.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sailor/comments/commentRss/217607.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sailor/services/trackbacks/217607.html</trackback:ping><description><![CDATA[     摘要: 定义         在一个方法中定义一个算法的骨架Q而将一些步骤gq到子类中。模板方法得子cd以在不改变算法结构的情况下,重新定义法中的某些 步骤?     钩子     钩子是一U被声明在抽象类中的ҎQ但只有I?..  <a href='http://www.aygfsteel.com/sailor/articles/217607.html'>阅读全文</a><img src ="http://www.aygfsteel.com/sailor/aggbug/217607.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sailor/" target="_blank">sailor</a> 2008-07-26 08:25 <a href="http://www.aygfsteel.com/sailor/articles/217607.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>模式Q八Q:外观QFacadeQ模?/title><link>http://www.aygfsteel.com/sailor/articles/217379.html</link><dc:creator>sailor</dc:creator><author>sailor</author><pubDate>Fri, 25 Jul 2008 02:26:00 GMT</pubDate><guid>http://www.aygfsteel.com/sailor/articles/217379.html</guid><wfw:comment>http://www.aygfsteel.com/sailor/comments/217379.html</wfw:comment><comments>http://www.aygfsteel.com/sailor/articles/217379.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sailor/comments/commentRss/217379.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sailor/services/trackbacks/217379.html</trackback:ping><description><![CDATA[<p><strong>定义</strong><br />    提供了一个统一的接口,用来讉K字系l中的一接口,外观定义了一个高层接口,让子pȝ更容易用?br /> <br /> <strong>要点</strong><br />      当需要简化ƈl一一个很大的接口或者一复杂的接口Ӟ使用外观?br /> <br />     外观客户从一个复杂的子系l中解耦?/p> <br />     实现一个外观,需要将子系l组合进外观中,然后工作委托给子系l执行?br /> <br />     外观一对?#8220;包装”h以简化其接口?br /> <br /> <strong>实例</strong><br />     <img style="width: 531px; height: 411px" height="411" alt="" src="http://www.aygfsteel.com/images/blogjava_net/sailor/UML/adapter.gif" width="531" border="0" /><br /> <br /> 例子Qhttp://www.jdon.com/designpatterns/designpattern_Facade.htm<br /> <br /> 参考资料:《First Head 设计模式?br />                     http://www.jdon.com/designpatterns/designpattern_Facade.htm <img src ="http://www.aygfsteel.com/sailor/aggbug/217379.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sailor/" target="_blank">sailor</a> 2008-07-25 10:26 <a href="http://www.aygfsteel.com/sailor/articles/217379.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>模式Q七Q:适配器(AdapterQ模?/title><link>http://www.aygfsteel.com/sailor/articles/217347.html</link><dc:creator>sailor</dc:creator><author>sailor</author><pubDate>Fri, 25 Jul 2008 01:17:00 GMT</pubDate><guid>http://www.aygfsteel.com/sailor/articles/217347.html</guid><wfw:comment>http://www.aygfsteel.com/sailor/comments/217347.html</wfw:comment><comments>http://www.aygfsteel.com/sailor/articles/217347.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sailor/comments/commentRss/217347.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sailor/services/trackbacks/217347.html</trackback:ping><description><![CDATA[<p><strong>定义<br /> </strong>    一个类的接口,转换成客h望的另一个接口。适配器让原本不兼容的cd以合作无间?br /> <span style="font-size: 14pt; font-family: 'Times New Roman'"><br /> <font size="3">    c适配器可以分为类适配器和对象适配?/font><br /> </span><br /> <img height="339" alt="adapter.bmp" src="http://www.aygfsteel.com/images/blogjava_net/flying/adapter.bmp" width="481" align="center" border="0" /><br /> <strong>实用?br /> </strong>    当需要私用一个现有的c而其接口q不W合你需要的Ӟ׃用适配器;<br /> <br />     适配器改变接口以W合用户的期望;<br /> <br /> <strong>实例<br /> <br /> <img alt="" src="http://www.aygfsteel.com/images/blogjava_net/sailor/adapter.JPG" border="0" /><br /> <br /> <br /> </strong></p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080"> 1</span><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">package</span><span style="color: #000000"> com.sailor.adapter;<br /> </span><span style="color: #008080"> 2</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> </span><span style="color: #008080"> 3</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> </span><span style="color: #008080"> 4</span><span style="color: #000000"><img id="Codehighlighter1_30_89_Open_Image" onclick="this.style.display='none'; Codehighlighter1_30_89_Open_Text.style.display='none'; Codehighlighter1_30_89_Closed_Image.style.display='inline'; Codehighlighter1_30_89_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_30_89_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_30_89_Closed_Text.style.display='none'; Codehighlighter1_30_89_Open_Image.style.display='inline'; Codehighlighter1_30_89_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span id="Codehighlighter1_30_89_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_30_89_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"><br /> </span><span style="color: #008080"> 5</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * 被适配?br /> </span><span style="color: #008080"> 6</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * </span><span style="color: #808080">@author</span><span style="color: #008000"> sailor<br /> </span><span style="color: #008080"> 7</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * Jul 25, 2008 9:35:19 AM<br /> </span><span style="color: #008080"> 8</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /> </span><span style="color: #008080"> 9</span><span style="color: #000000"><img id="Codehighlighter1_109_252_Open_Image" onclick="this.style.display='none'; Codehighlighter1_109_252_Open_Text.style.display='none'; Codehighlighter1_109_252_Closed_Image.style.display='inline'; Codehighlighter1_109_252_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_109_252_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_109_252_Closed_Text.style.display='none'; Codehighlighter1_109_252_Open_Image.style.display='inline'; Codehighlighter1_109_252_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Duck </span><span id="Codehighlighter1_109_252_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_109_252_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">10</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    <br /> </span><span style="color: #008080">11</span><span style="color: #000000"><img id="Codehighlighter1_128_132_Open_Image" onclick="this.style.display='none'; Codehighlighter1_128_132_Open_Text.style.display='none'; Codehighlighter1_128_132_Closed_Image.style.display='inline'; Codehighlighter1_128_132_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_128_132_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_128_132_Closed_Text.style.display='none'; Codehighlighter1_128_132_Open_Image.style.display='inline'; Codehighlighter1_128_132_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> Duck() </span><span id="Codehighlighter1_128_132_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_128_132_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080">13</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080">15</span><span style="color: #000000"><img id="Codehighlighter1_153_191_Open_Image" onclick="this.style.display='none'; Codehighlighter1_153_191_Open_Text.style.display='none'; Codehighlighter1_153_191_Closed_Image.style.display='inline'; Codehighlighter1_153_191_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_153_191_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_153_191_Closed_Text.style.display='none'; Codehighlighter1_153_191_Open_Image.style.display='inline'; Codehighlighter1_153_191_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> fly()</span><span id="Codehighlighter1_153_191_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_153_191_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">16</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">I can fly</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> </span><span style="color: #008080">17</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    <br /> </span><span style="color: #008080">19</span><span style="color: #000000"><img id="Codehighlighter1_215_250_Open_Image" onclick="this.style.display='none'; Codehighlighter1_215_250_Open_Text.style.display='none'; Codehighlighter1_215_250_Closed_Image.style.display='inline'; Codehighlighter1_215_250_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_215_250_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_215_250_Closed_Text.style.display='none'; Codehighlighter1_215_250_Open_Image.style.display='inline'; Codehighlighter1_215_250_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> quack()</span><span id="Codehighlighter1_215_250_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_215_250_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">20</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">quake!</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> </span><span style="color: #008080">21</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">22</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">23</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span></div> <p><br />  </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080"> 1</span><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #000000"><br /> </span><span style="color: #008080"> 2</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">package</span><span style="color: #000000"> com.sailor.adapter;<br /> </span><span style="color: #008080"> 3</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> </span><span style="color: #008080"> 4</span><span style="color: #000000"><img id="Codehighlighter1_30_89_Open_Image" onclick="this.style.display='none'; Codehighlighter1_30_89_Open_Text.style.display='none'; Codehighlighter1_30_89_Closed_Image.style.display='inline'; Codehighlighter1_30_89_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_30_89_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_30_89_Closed_Text.style.display='none'; Codehighlighter1_30_89_Open_Image.style.display='inline'; Codehighlighter1_30_89_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span id="Codehighlighter1_30_89_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_30_89_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"><br /> </span><span style="color: #008080"> 5</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * 目标接口<br /> </span><span style="color: #008080"> 6</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * </span><span style="color: #808080">@author</span><span style="color: #008000"> sailor<br /> </span><span style="color: #008080"> 7</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * Jul 25, 2008 9:43:35 AM<br /> </span><span style="color: #008080"> 8</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /> </span><span style="color: #008080"> 9</span><span style="color: #000000"><img id="Codehighlighter1_115_161_Open_Image" onclick="this.style.display='none'; Codehighlighter1_115_161_Open_Text.style.display='none'; Codehighlighter1_115_161_Closed_Image.style.display='inline'; Codehighlighter1_115_161_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_115_161_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_115_161_Closed_Text.style.display='none'; Codehighlighter1_115_161_Open_Image.style.display='inline'; Codehighlighter1_115_161_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">interface</span><span style="color: #000000"> Turkey </span><span id="Codehighlighter1_115_161_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_115_161_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">10</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080">11</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> gobble();<br /> </span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> fly();<br /> </span><span style="color: #008080">13</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span></div> <p><br />  </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080"> 1</span><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #000000"><br /> </span><span style="color: #008080"> 2</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">package</span><span style="color: #000000"> com.sailor.adapter;<br /> </span><span style="color: #008080"> 3</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> </span><span style="color: #008080"> 4</span><span style="color: #000000"><img id="Codehighlighter1_30_88_Open_Image" onclick="this.style.display='none'; Codehighlighter1_30_88_Open_Text.style.display='none'; Codehighlighter1_30_88_Closed_Image.style.display='inline'; Codehighlighter1_30_88_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_30_88_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_30_88_Closed_Text.style.display='none'; Codehighlighter1_30_88_Open_Image.style.display='inline'; Codehighlighter1_30_88_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span id="Codehighlighter1_30_88_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_30_88_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"><br /> </span><span style="color: #008080"> 5</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * 适配?br /> </span><span style="color: #008080"> 6</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * </span><span style="color: #808080">@author</span><span style="color: #008000"> sailor<br /> </span><span style="color: #008080"> 7</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * Jul 25, 2008 9:38:10 AM<br /> </span><span style="color: #008080"> 8</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /> </span><span style="color: #008080"> 9</span><span style="color: #000000"><img id="Codehighlighter1_134_303_Open_Image" onclick="this.style.display='none'; Codehighlighter1_134_303_Open_Text.style.display='none'; Codehighlighter1_134_303_Closed_Image.style.display='inline'; Codehighlighter1_134_303_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_134_303_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_134_303_Closed_Text.style.display='none'; Codehighlighter1_134_303_Open_Image.style.display='inline'; Codehighlighter1_134_303_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> TurkeyAdapter </span><span style="color: #0000ff">implements</span><span style="color: #000000"> Turkey</span><span id="Codehighlighter1_134_303_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_134_303_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">10</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080">11</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">private</span><span style="color: #000000"> Duck duck;<br /> </span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080">13</span><span style="color: #000000"><img id="Codehighlighter1_191_214_Open_Image" onclick="this.style.display='none'; Codehighlighter1_191_214_Open_Text.style.display='none'; Codehighlighter1_191_214_Closed_Image.style.display='inline'; Codehighlighter1_191_214_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_191_214_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_191_214_Closed_Text.style.display='none'; Codehighlighter1_191_214_Open_Image.style.display='inline'; Codehighlighter1_191_214_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> TurkeyAdapter(Duck duck) </span><span id="Codehighlighter1_191_214_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_191_214_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">this</span><span style="color: #000000">.duck </span><span style="color: #000000">=</span><span style="color: #000000"> duck;<br /> </span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">16</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    <br /> </span><span style="color: #008080">17</span><span style="color: #000000"><img id="Codehighlighter1_239_258_Open_Image" onclick="this.style.display='none'; Codehighlighter1_239_258_Open_Text.style.display='none'; Codehighlighter1_239_258_Closed_Image.style.display='inline'; Codehighlighter1_239_258_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_239_258_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_239_258_Closed_Text.style.display='none'; Codehighlighter1_239_258_Open_Image.style.display='inline'; Codehighlighter1_239_258_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> gobble()</span><span id="Codehighlighter1_239_258_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_239_258_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        duck.quack();<br /> </span><span style="color: #008080">19</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">20</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    <br /> </span><span style="color: #008080">21</span><span style="color: #000000"><img id="Codehighlighter1_280_297_Open_Image" onclick="this.style.display='none'; Codehighlighter1_280_297_Open_Text.style.display='none'; Codehighlighter1_280_297_Closed_Image.style.display='inline'; Codehighlighter1_280_297_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_280_297_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_280_297_Closed_Text.style.display='none'; Codehighlighter1_280_297_Open_Image.style.display='inline'; Codehighlighter1_280_297_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> fly()</span><span id="Codehighlighter1_280_297_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_280_297_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">22</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        duck.fly();<br /> </span><span style="color: #008080">23</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">24</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    <br /> </span><span style="color: #008080">25</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    <br /> </span><span style="color: #008080">26</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">27</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span></div> <p><br />  </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080"> 1</span><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #000000"><br /> </span><span style="color: #008080"> 2</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">package</span><span style="color: #000000"> com.sailor.adapter;<br /> </span><span style="color: #008080"> 3</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> </span><span style="color: #008080"> 4</span><span style="color: #000000"><img id="Codehighlighter1_30_88_Open_Image" onclick="this.style.display='none'; Codehighlighter1_30_88_Open_Text.style.display='none'; Codehighlighter1_30_88_Closed_Image.style.display='inline'; Codehighlighter1_30_88_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_30_88_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_30_88_Closed_Text.style.display='none'; Codehighlighter1_30_88_Open_Image.style.display='inline'; Codehighlighter1_30_88_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span id="Codehighlighter1_30_88_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_30_88_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"><br /> </span><span style="color: #008080"> 5</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * 客户?br /> </span><span style="color: #008080"> 6</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * </span><span style="color: #808080">@author</span><span style="color: #008000"> sailor<br /> </span><span style="color: #008080"> 7</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * Jul 25, 2008 9:45:29 AM<br /> </span><span style="color: #008080"> 8</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /> </span><span style="color: #008080"> 9</span><span style="color: #000000"><img id="Codehighlighter1_110_298_Open_Image" onclick="this.style.display='none'; Codehighlighter1_110_298_Open_Text.style.display='none'; Codehighlighter1_110_298_Closed_Image.style.display='inline'; Codehighlighter1_110_298_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_110_298_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_110_298_Closed_Text.style.display='none'; Codehighlighter1_110_298_Open_Image.style.display='inline'; Codehighlighter1_110_298_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Client </span><span id="Codehighlighter1_110_298_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_110_298_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">10</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080">11</span><span style="color: #000000"><img id="Codehighlighter1_114_137_Open_Image" onclick="this.style.display='none'; Codehighlighter1_114_137_Open_Text.style.display='none'; Codehighlighter1_114_137_Closed_Image.style.display='inline'; Codehighlighter1_114_137_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_114_137_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_114_137_Closed_Text.style.display='none'; Codehighlighter1_114_137_Open_Image.style.display='inline'; Codehighlighter1_114_137_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span id="Codehighlighter1_114_137_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_114_137_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"><br /> </span><span style="color: #008080">12</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />     * </span><span style="color: #808080">@param</span><span style="color: #008000"> args<br /> </span><span style="color: #008080">13</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />     </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">14</span><span style="color: #000000"><img id="Codehighlighter1_179_295_Open_Image" onclick="this.style.display='none'; Codehighlighter1_179_295_Open_Text.style.display='none'; Codehighlighter1_179_295_Closed_Image.style.display='inline'; Codehighlighter1_179_295_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_179_295_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_179_295_Closed_Text.style.display='none'; Codehighlighter1_179_295_Open_Image.style.display='inline'; Codehighlighter1_179_295_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String[] args) </span><span id="Codehighlighter1_179_295_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_179_295_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        <br /> </span><span style="color: #008080">16</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        Duck duck </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Duck();<br /> </span><span style="color: #008080">17</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        <br /> </span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        Turkey turkey </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> TurkeyAdapter(duck);<br /> </span><span style="color: #008080">19</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        <br /> </span><span style="color: #008080">20</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        turkey.gobble();<br /> </span><span style="color: #008080">21</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        turkey.fly();<br /> </span><span style="color: #008080">22</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">23</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080">24</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">25</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span></div> <p><br />     参考资料:《First Head 设计模式?/p> <img src ="http://www.aygfsteel.com/sailor/aggbug/217347.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sailor/" target="_blank">sailor</a> 2008-07-25 09:17 <a href="http://www.aygfsteel.com/sailor/articles/217347.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>模式Q六Q:命oQCommandQ模?/title><link>http://www.aygfsteel.com/sailor/articles/217246.html</link><dc:creator>sailor</dc:creator><author>sailor</author><pubDate>Thu, 24 Jul 2008 09:20:00 GMT</pubDate><guid>http://www.aygfsteel.com/sailor/articles/217246.html</guid><wfw:comment>http://www.aygfsteel.com/sailor/comments/217246.html</wfw:comment><comments>http://www.aygfsteel.com/sailor/articles/217246.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sailor/comments/commentRss/217246.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sailor/services/trackbacks/217246.html</trackback:ping><description><![CDATA[<p><strong>定义</strong><br />     ?#8220;h”装成对象,以便使用不同的请求、队列或者日志来参数化其他对象。命令模式也支持可撤销的操作?br /> <br /> <strong>要点<br /> </strong>    命o模式发求的对象和接受请求的对象解耦;<br /> <br />     在被解耦的两者之间是通过命o对象q行沟通的。命令对象封装了接收者和一个或者一l对象;<br /> <br />     调用者通过调用命o对象的execute()发出hQ这会得接受者的动作被调用;<br /> <br />     调用者可以接受命令当作参敎ͼ甚至在运行时动态地q行Q?br /> <br />     命o也可以实现日志和实务pȝ?br /> <br /> <br /> <strong>所涉及的角Ԍ<br /> 1.客户QClientQ角Ԍ</strong>创徏一个具体对象及其确定接收?<br /> <strong>2.命oQCommandQ角?</strong>声明了一个给所有具体命令类的抽象接口?br /> <strong>3.具体命o(ConcreteCommand)角色:</strong>定义一个接收者与行ؓ之间的弱耦合Q实现exceute()ҎQ负责调用接收者的相应操作<strong>?br /> 4.h?Invoker)角色:</strong>负责调用命o对象执行h?br /> <strong>5.接收者(ReceviceQ角?</strong>负责具体实施与执行一个请求?br /> <strong><img height="265" alt="commmand.bmp" src="http://www.aygfsteel.com/images/blogjava_net/flying/commmand.bmp" width="602" border="0" /><br /> 优点Q?br /> </strong>解耦了发送者和接受者之间联pR?发送者调用一个操作,接受者接受请求执行相应的动作Q因Z用Command模式解耦,发送者无需知道接受者Q何接口?br /> <br /> <strong>命o模式创徏的一般步?/strong>Q?br /> 1.客户端创Z个ConcreteCommand对象Qƈ指明接收者?br /> 2.h对象保持ConcreteCommand对象?br /> 3.h对象通过调用actionҎ发出hQ若命o是可撤消,则ConcreteCommand保存execute()Ҏ执行前的状态?br /> 4.ConcreteCommand对象调用接收的方法执行请求?br /> <br /> <strong>实例<br /> 抽象命o接口Q?br /> </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">package</span><span style="color: #000000"> command;<br /> <img id="Codehighlighter1_41_69_Open_Image" onclick="this.style.display='none'; Codehighlighter1_41_69_Open_Text.style.display='none'; Codehighlighter1_41_69_Closed_Image.style.display='inline'; Codehighlighter1_41_69_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_41_69_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_41_69_Closed_Text.style.display='none'; Codehighlighter1_41_69_Open_Image.style.display='inline'; Codehighlighter1_41_69_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">interface</span><span style="color: #000000"> Command</span><span id="Codehighlighter1_41_69_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_41_69_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #008000">//</span><span style="color: #008000">执行Ҏ</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">     </span><span style="color: #0000ff">void</span><span style="color: #000000"> execute();<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span></div> <p>具体命o<br /> </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">package</span><span style="color: #000000"> command;<br /> <img id="Codehighlighter1_64_238_Open_Image" onclick="this.style.display='none'; Codehighlighter1_64_238_Open_Text.style.display='none'; Codehighlighter1_64_238_Closed_Image.style.display='inline'; Codehighlighter1_64_238_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_64_238_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_64_238_Closed_Text.style.display='none'; Codehighlighter1_64_238_Open_Image.style.display='inline'; Codehighlighter1_64_238_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> ConcreteCommand </span><span style="color: #0000ff">implements</span><span style="color: #000000"> Command</span><span id="Codehighlighter1_64_238_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_64_238_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #008000">//</span><span style="color: #008000">接收?/span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">    </span><span style="color: #0000ff">private</span><span style="color: #000000"> Receiver receiver;<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #008000">//</span><span style="color: #008000">构造方?/span><span style="color: #008000"><br /> <img id="Codehighlighter1_151_180_Open_Image" onclick="this.style.display='none'; Codehighlighter1_151_180_Open_Text.style.display='none'; Codehighlighter1_151_180_Closed_Image.style.display='inline'; Codehighlighter1_151_180_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_151_180_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_151_180_Closed_Text.style.display='none'; Codehighlighter1_151_180_Open_Image.style.display='inline'; Codehighlighter1_151_180_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #000000">    </span><span style="color: #0000ff">public</span><span style="color: #000000"> ConcreteCommand(Receiver receiver)</span><span id="Codehighlighter1_151_180_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_151_180_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">this</span><span style="color: #000000">.receiver</span><span style="color: #000000">=</span><span style="color: #000000">receiver;<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #008000">//</span><span style="color: #008000">执行Ҏ</span><span style="color: #008000"><br /> <img id="Codehighlighter1_212_236_Open_Image" onclick="this.style.display='none'; Codehighlighter1_212_236_Open_Text.style.display='none'; Codehighlighter1_212_236_Closed_Image.style.display='inline'; Codehighlighter1_212_236_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_212_236_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_212_236_Closed_Text.style.display='none'; Codehighlighter1_212_236_Open_Image.style.display='inline'; Codehighlighter1_212_236_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #000000">    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> execute()</span><span id="Codehighlighter1_212_236_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_212_236_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />        receiver.action();<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span></div> <p>接收者:<br /> </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">package</span><span style="color: #000000"> command;<br /> <img id="Codehighlighter1_40_152_Open_Image" onclick="this.style.display='none'; Codehighlighter1_40_152_Open_Text.style.display='none'; Codehighlighter1_40_152_Closed_Image.style.display='inline'; Codehighlighter1_40_152_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_40_152_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_40_152_Closed_Text.style.display='none'; Codehighlighter1_40_152_Open_Image.style.display='inline'; Codehighlighter1_40_152_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000">  </span><span style="color: #0000ff">class</span><span style="color: #000000"> Receiver </span><span id="Codehighlighter1_40_152_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_40_152_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #008000">//</span><span style="color: #008000">构造方?/span><span style="color: #008000"><br /> <img id="Codehighlighter1_68_69_Open_Image" onclick="this.style.display='none'; Codehighlighter1_68_69_Open_Text.style.display='none'; Codehighlighter1_68_69_Closed_Image.style.display='inline'; Codehighlighter1_68_69_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_68_69_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_68_69_Closed_Text.style.display='none'; Codehighlighter1_68_69_Open_Image.style.display='inline'; Codehighlighter1_68_69_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #000000">    </span><span style="color: #0000ff">public</span><span style="color: #000000"> Receiver()</span><span id="Codehighlighter1_68_69_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_68_69_Open_Text"><span style="color: #000000">{}</span></span><span style="color: #000000">;<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #008000">//</span><span style="color: #008000">行ؓҎ</span><span style="color: #008000"><br /> <img id="Codehighlighter1_101_150_Open_Image" onclick="this.style.display='none'; Codehighlighter1_101_150_Open_Text.style.display='none'; Codehighlighter1_101_150_Closed_Image.style.display='inline'; Codehighlighter1_101_150_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_101_150_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_101_150_Closed_Text.style.display='none'; Codehighlighter1_101_150_Open_Image.style.display='inline'; Codehighlighter1_101_150_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #000000">    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> action()</span><span id="Codehighlighter1_101_150_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_101_150_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">Action is taken here</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span></div> <p>h者:<br /> </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">package</span><span style="color: #000000"> command;<br /> <img id="Codehighlighter1_37_195_Open_Image" onclick="this.style.display='none'; Codehighlighter1_37_195_Open_Text.style.display='none'; Codehighlighter1_37_195_Closed_Image.style.display='inline'; Codehighlighter1_37_195_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_37_195_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_37_195_Closed_Text.style.display='none'; Codehighlighter1_37_195_Open_Image.style.display='inline'; Codehighlighter1_37_195_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Invoker</span><span id="Codehighlighter1_37_195_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_37_195_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #008000">//</span><span style="color: #008000">命o</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">    </span><span style="color: #0000ff">private</span><span style="color: #000000"> Command command;<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #008000">//</span><span style="color: #008000">构造方?/span><span style="color: #008000"><br /> <img id="Codehighlighter1_111_138_Open_Image" onclick="this.style.display='none'; Codehighlighter1_111_138_Open_Text.style.display='none'; Codehighlighter1_111_138_Closed_Image.style.display='inline'; Codehighlighter1_111_138_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_111_138_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_111_138_Closed_Text.style.display='none'; Codehighlighter1_111_138_Open_Image.style.display='inline'; Codehighlighter1_111_138_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #000000">    </span><span style="color: #0000ff">public</span><span style="color: #000000"> Invoker(Command command)</span><span id="Codehighlighter1_111_138_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_111_138_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">this</span><span style="color: #000000">.command</span><span style="color: #000000">=</span><span style="color: #000000">command;<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #008000">//</span><span style="color: #008000">行ؓҎ</span><span style="color: #008000"><br /> <img id="Codehighlighter1_169_193_Open_Image" onclick="this.style.display='none'; Codehighlighter1_169_193_Open_Text.style.display='none'; Codehighlighter1_169_193_Closed_Image.style.display='inline'; Codehighlighter1_169_193_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_169_193_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_169_193_Closed_Text.style.display='none'; Codehighlighter1_169_193_Open_Image.style.display='inline'; Codehighlighter1_169_193_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #000000">    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> action()</span><span id="Codehighlighter1_169_193_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_169_193_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />        command.execute();<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span></div> <p>客户端:<br /> </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">package</span><span style="color: #000000"> command;<br /> <img id="Codehighlighter1_36_243_Open_Image" onclick="this.style.display='none'; Codehighlighter1_36_243_Open_Text.style.display='none'; Codehighlighter1_36_243_Closed_Image.style.display='inline'; Codehighlighter1_36_243_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_36_243_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_36_243_Closed_Text.style.display='none'; Codehighlighter1_36_243_Open_Image.style.display='inline'; Codehighlighter1_36_243_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Client</span><span id="Codehighlighter1_36_243_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_36_243_Open_Text"><span style="color: #000000">{<br /> <img id="Codehighlighter1_77_241_Open_Image" onclick="this.style.display='none'; Codehighlighter1_77_241_Open_Text.style.display='none'; Codehighlighter1_77_241_Closed_Image.style.display='inline'; Codehighlighter1_77_241_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_77_241_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_77_241_Closed_Text.style.display='none'; Codehighlighter1_77_241_Open_Image.style.display='inline'; Codehighlighter1_77_241_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String[] args)</span><span id="Codehighlighter1_77_241_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_77_241_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />        Receiver receiver</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> Receiver();<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />        Command concreteCommand</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> ConcreteCommand(receiver);<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />        Invoker invoker</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> Invoker(concreteCommand);<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" alt="" />        invoker.action();<br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span></div> <p>命o模式与责任链模式区别Q?br /> 责Q链模式一个特定的h接收对象对请求与命o的执行变得不定?而命令模式得一个特定的对象对命令的执行变得明显与确?<br /> <br /> 参考资料:《First Head 设计模式?br />                         <a id="viewpost1_TitleUrl" href="http://www.aygfsteel.com/flying/archive/2006/08/15/63773.html">设计模式学习W记(十五)--------命o(Command)模式</a></strong></p> <img src ="http://www.aygfsteel.com/sailor/aggbug/217246.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sailor/" target="_blank">sailor</a> 2008-07-24 17:20 <a href="http://www.aygfsteel.com/sailor/articles/217246.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>模式Q五Q:单gQsingletonQ模?/title><link>http://www.aygfsteel.com/sailor/articles/216787.html</link><dc:creator>sailor</dc:creator><author>sailor</author><pubDate>Wed, 23 Jul 2008 01:51:00 GMT</pubDate><guid>http://www.aygfsteel.com/sailor/articles/216787.html</guid><wfw:comment>http://www.aygfsteel.com/sailor/comments/216787.html</wfw:comment><comments>http://www.aygfsteel.com/sailor/articles/216787.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sailor/comments/commentRss/216787.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sailor/services/trackbacks/216787.html</trackback:ping><description><![CDATA[<p>定义<br />     保一个类只有一个实例,q提供全局讉K?br /> <br /> 设计原则<br />     在JAVA中实现单件模式需要一个私有的构造器、一个静态方法和一个静态变量;<br />     定在性能和资源上的限Ӟ然后心地选择适当的方案来实现单gQ以解决多线E的问题Q?br />     如果不是采用W五版的java 2Q双重检查锁实现会失效;<br />     <br /> 实现<br />     1、lazy singleton<br /> </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080"> 1</span><img id="Codehighlighter1_22_248_Open_Image" onclick="this.style.display='none'; Codehighlighter1_22_248_Open_Text.style.display='none'; Codehighlighter1_22_248_Closed_Image.style.display='inline'; Codehighlighter1_22_248_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_22_248_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_22_248_Closed_Text.style.display='none'; Codehighlighter1_22_248_Open_Image.style.display='inline'; Codehighlighter1_22_248_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Singleton</span><span id="Codehighlighter1_22_248_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_22_248_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080"> 2</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> </span><span style="color: #008080"> 3</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> Singleton uniqueInstance;<br /> </span><span style="color: #008080"> 4</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> </span><span style="color: #008080"> 5</span><span style="color: #000000"><img id="Codehighlighter1_88_89_Open_Image" onclick="this.style.display='none'; Codehighlighter1_88_89_Open_Text.style.display='none'; Codehighlighter1_88_89_Closed_Image.style.display='inline'; Codehighlighter1_88_89_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_88_89_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_88_89_Closed_Text.style.display='none'; Codehighlighter1_88_89_Open_Image.style.display='inline'; Codehighlighter1_88_89_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /> </span><span style="color: #0000ff">private</span><span style="color: #000000"> Singleton()</span><span id="Codehighlighter1_88_89_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_88_89_Open_Text"><span style="color: #000000">{}</span></span><span style="color: #000000">  </span><span style="color: #008000">//</span><span style="color: #008000">U有构造器</span><span style="color: #008000"><br /> </span><span style="color: #008080"> 6</span><span style="color: #008000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000"><br /> </span><span style="color: #008080"> 7</span><span style="color: #000000"><img id="Codehighlighter1_139_246_Open_Image" onclick="this.style.display='none'; Codehighlighter1_139_246_Open_Text.style.display='none'; Codehighlighter1_139_246_Closed_Image.style.display='inline'; Codehighlighter1_139_246_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_139_246_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_139_246_Closed_Text.style.display='none'; Codehighlighter1_139_246_Open_Image.style.display='inline'; Codehighlighter1_139_246_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> Singleton getInstance()</span><span id="Codehighlighter1_139_246_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_139_246_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080"> 8</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> </span><span style="color: #008080"> 9</span><span style="color: #000000"><img id="Codehighlighter1_170_215_Open_Image" onclick="this.style.display='none'; Codehighlighter1_170_215_Open_Text.style.display='none'; Codehighlighter1_170_215_Closed_Image.style.display='inline'; Codehighlighter1_170_215_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_170_215_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_170_215_Closed_Text.style.display='none'; Codehighlighter1_170_215_Open_Image.style.display='inline'; Codehighlighter1_170_215_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span><span style="color: #0000ff">if</span><span style="color: #000000">(uniqueInstance </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">)</span><span id="Codehighlighter1_170_215_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_170_215_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">10</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />   <br /> </span><span style="color: #008080">11</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />   uniqueInstance </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Singleton();<br /> </span><span style="color: #008080">12</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />  }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">13</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />  <br /> </span><span style="color: #008080">14</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span><span style="color: #0000ff">return</span><span style="color: #000000"> uniqueSingleton<br /> </span><span style="color: #008080">15</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /> }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">16</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div> <p>    <br />     2、处理多U程<br />              q是保证可行的最直接做法Q对于性能如果没有考虑Q可以直接用q个Ҏ?/p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080"> 1</span><img id="Codehighlighter1_22_261_Open_Image" onclick="this.style.display='none'; Codehighlighter1_22_261_Open_Text.style.display='none'; Codehighlighter1_22_261_Closed_Image.style.display='inline'; Codehighlighter1_22_261_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_22_261_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_22_261_Closed_Text.style.display='none'; Codehighlighter1_22_261_Open_Image.style.display='inline'; Codehighlighter1_22_261_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Singleton</span><span id="Codehighlighter1_22_261_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_22_261_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080"> 2</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> </span><span style="color: #008080"> 3</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> Singleton uniqueInstance;<br /> </span><span style="color: #008080"> 4</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> </span><span style="color: #008080"> 5</span><span style="color: #000000"><img id="Codehighlighter1_88_89_Open_Image" onclick="this.style.display='none'; Codehighlighter1_88_89_Open_Text.style.display='none'; Codehighlighter1_88_89_Closed_Image.style.display='inline'; Codehighlighter1_88_89_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_88_89_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_88_89_Closed_Text.style.display='none'; Codehighlighter1_88_89_Open_Image.style.display='inline'; Codehighlighter1_88_89_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /> </span><span style="color: #0000ff">private</span><span style="color: #000000"> Singleton()</span><span id="Codehighlighter1_88_89_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_88_89_Open_Text"><span style="color: #000000">{}</span></span><span style="color: #000000">  </span><span style="color: #008000">//</span><span style="color: #008000">U有构造器</span><span style="color: #008000"><br /> </span><span style="color: #008080"> 6</span><span style="color: #008000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000"><br /> </span><span style="color: #008080"> 7</span><span style="color: #000000"><img id="Codehighlighter1_152_259_Open_Image" onclick="this.style.display='none'; Codehighlighter1_152_259_Open_Text.style.display='none'; Codehighlighter1_152_259_Closed_Image.style.display='inline'; Codehighlighter1_152_259_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_152_259_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_152_259_Closed_Text.style.display='none'; Codehighlighter1_152_259_Open_Image.style.display='inline'; Codehighlighter1_152_259_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: red"><strong>synchronized</strong></span><span style="color: #000000"> Singleton getInstance()</span><span id="Codehighlighter1_152_259_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_152_259_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080"> 8</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> </span><span style="color: #008080"> 9</span><span style="color: #000000"><img id="Codehighlighter1_183_228_Open_Image" onclick="this.style.display='none'; Codehighlighter1_183_228_Open_Text.style.display='none'; Codehighlighter1_183_228_Closed_Image.style.display='inline'; Codehighlighter1_183_228_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_183_228_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_183_228_Closed_Text.style.display='none'; Codehighlighter1_183_228_Open_Image.style.display='inline'; Codehighlighter1_183_228_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span><span style="color: #0000ff">if</span><span style="color: #000000">(uniqueInstance </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">)</span><span id="Codehighlighter1_183_228_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_183_228_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">10</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />   <br /> </span><span style="color: #008080">11</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />   uniqueInstance </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Singleton();<br /> </span><span style="color: #008080">12</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />  }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">13</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />  <br /> </span><span style="color: #008080">14</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span><span style="color: #0000ff">return</span><span style="color: #000000"> uniqueSingleton<br /> </span><span style="color: #008080">15</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /> }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">16</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div> <br />     3、急切实例?br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080"> 1</span><img id="Codehighlighter1_22_173_Open_Image" onclick="this.style.display='none'; Codehighlighter1_22_173_Open_Text.style.display='none'; Codehighlighter1_22_173_Closed_Image.style.display='inline'; Codehighlighter1_22_173_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_22_173_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_22_173_Closed_Text.style.display='none'; Codehighlighter1_22_173_Open_Image.style.display='inline'; Codehighlighter1_22_173_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Singleton</span><span id="Codehighlighter1_22_173_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_22_173_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080"> 2</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /> <br /> </span><span style="color: #008080"> 3</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> uniqueInstance </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Singleton();<br /> </span><span style="color: #008080"> 4</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> </span><span style="color: #008080"> 5</span><span style="color: #000000"><img id="Codehighlighter1_97_98_Open_Image" onclick="this.style.display='none'; Codehighlighter1_97_98_Open_Text.style.display='none'; Codehighlighter1_97_98_Closed_Image.style.display='inline'; Codehighlighter1_97_98_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_97_98_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_97_98_Closed_Text.style.display='none'; Codehighlighter1_97_98_Open_Image.style.display='inline'; Codehighlighter1_97_98_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /> </span><span style="color: #0000ff">private</span><span style="color: #000000"> Singleton()</span><span id="Codehighlighter1_97_98_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_97_98_Open_Text"><span style="color: #000000">{}</span></span><span style="color: #000000"><br /> </span><span style="color: #008080"> 6</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> </span><span style="color: #008080"> 7</span><span style="color: #000000"><img id="Codehighlighter1_139_170_Open_Image" onclick="this.style.display='none'; Codehighlighter1_139_170_Open_Text.style.display='none'; Codehighlighter1_139_170_Closed_Image.style.display='inline'; Codehighlighter1_139_170_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_139_170_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_139_170_Closed_Text.style.display='none'; Codehighlighter1_139_170_Open_Image.style.display='inline'; Codehighlighter1_139_170_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /> </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> Singleton getInstance()</span><span id="Codehighlighter1_139_170_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_139_170_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080"> 8</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /> <br /> </span><span style="color: #008080"> 9</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />   </span><span style="color: #0000ff">return</span><span style="color: #000000"> uniqueInstance;<br /> </span><span style="color: #008080">10</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /> }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">11</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> </span><span style="color: #008080">12</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div> <br /> <br />     4、用“双重查加?#8221;Q在getInstance( )中减用同?br />     ׃没有性能上考虑Q所以这个方法似乎杀鸡用了牛刀。另外这个方法还得确定用的是java5以上的版本?br /> <br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080"> 1</span><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">package</span><span style="color: #000000"> com.sailor.singleton;<br /> </span><span style="color: #008080"> 2</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><br /> </span><span style="color: #008080"> 3</span><span style="color: #000000"><img id="Codehighlighter1_31_82_Open_Image" onclick="this.style.display='none'; Codehighlighter1_31_82_Open_Text.style.display='none'; Codehighlighter1_31_82_Closed_Image.style.display='inline'; Codehighlighter1_31_82_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_31_82_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_31_82_Closed_Text.style.display='none'; Codehighlighter1_31_82_Open_Image.style.display='inline'; Codehighlighter1_31_82_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span id="Codehighlighter1_31_82_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_31_82_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"><br /> </span><span style="color: #008080"> 4</span><span style="color: #008000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /> * </span><span style="color: #808080">@author</span><span style="color: #008000"> sailor<br /> </span><span style="color: #008080"> 5</span><span style="color: #008000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /> * Jul 23, 2008 9:46:17 AM<br /> </span><span style="color: #008080"> 6</span><span style="color: #008000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /> </span><span style="color: #008080"> 7</span><span style="color: #000000"><img id="Codehighlighter1_107_407_Open_Image" onclick="this.style.display='none'; Codehighlighter1_107_407_Open_Text.style.display='none'; Codehighlighter1_107_407_Closed_Image.style.display='inline'; Codehighlighter1_107_407_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_107_407_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_107_407_Closed_Text.style.display='none'; Codehighlighter1_107_407_Open_Image.style.display='inline'; Codehighlighter1_107_407_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Singleton </span><span id="Codehighlighter1_107_407_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_107_407_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080"> 8</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /> </span><span style="color: #008080"> 9</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">volatile</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> Singleton uniqueInstance;<br /> </span><span style="color: #008080">10</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /> </span><span style="color: #008080">11</span><span style="color: #000000"><img id="Codehighlighter1_184_185_Open_Image" onclick="this.style.display='none'; Codehighlighter1_184_185_Open_Text.style.display='none'; Codehighlighter1_184_185_Closed_Image.style.display='inline'; Codehighlighter1_184_185_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_184_185_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_184_185_Closed_Text.style.display='none'; Codehighlighter1_184_185_Open_Image.style.display='inline'; Codehighlighter1_184_185_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: #0000ff">private</span><span style="color: #000000"> Singleton()</span><span id="Codehighlighter1_184_185_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_184_185_Open_Text"><span style="color: #000000">{}</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">12</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /> </span><span style="color: #008080">13</span><span style="color: #000000"><img id="Codehighlighter1_227_405_Open_Image" onclick="this.style.display='none'; Codehighlighter1_227_405_Open_Text.style.display='none'; Codehighlighter1_227_405_Closed_Image.style.display='inline'; Codehighlighter1_227_405_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_227_405_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_227_405_Closed_Text.style.display='none'; Codehighlighter1_227_405_Open_Image.style.display='inline'; Codehighlighter1_227_405_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> Singleton getInstance()</span><span id="Codehighlighter1_227_405_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_227_405_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">14</span><span style="color: #000000"><img id="Codehighlighter1_257_377_Open_Image" onclick="this.style.display='none'; Codehighlighter1_257_377_Open_Text.style.display='none'; Codehighlighter1_257_377_Closed_Image.style.display='inline'; Codehighlighter1_257_377_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_257_377_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_257_377_Closed_Text.style.display='none'; Codehighlighter1_257_377_Open_Image.style.display='inline'; Codehighlighter1_257_377_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="color: #0000ff">if</span><span style="color: #000000">(uniqueInstance </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">)</span><span id="Codehighlighter1_257_377_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_257_377_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">15</span><span style="color: #000000"><img id="Codehighlighter1_291_373_Open_Image" onclick="this.style.display='none'; Codehighlighter1_291_373_Open_Text.style.display='none'; Codehighlighter1_291_373_Closed_Image.style.display='inline'; Codehighlighter1_291_373_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_291_373_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_291_373_Closed_Text.style.display='none'; Codehighlighter1_291_373_Open_Image.style.display='inline'; Codehighlighter1_291_373_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span><span style="color: #0000ff">synchronized</span><span style="color: #000000">(Singleton.</span><span style="color: #0000ff">class</span><span style="color: #000000">)</span><span id="Codehighlighter1_291_373_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_291_373_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">16</span><span style="color: #000000"><img id="Codehighlighter1_323_368_Open_Image" onclick="this.style.display='none'; Codehighlighter1_323_368_Open_Text.style.display='none'; Codehighlighter1_323_368_Closed_Image.style.display='inline'; Codehighlighter1_323_368_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_323_368_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_323_368_Closed_Text.style.display='none'; Codehighlighter1_323_368_Open_Image.style.display='inline'; Codehighlighter1_323_368_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />                </span><span style="color: #0000ff">if</span><span style="color: #000000">(uniqueInstance </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">)</span><span id="Codehighlighter1_323_368_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_323_368_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">17</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />                    uniqueInstance </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Singleton();<br /> </span><span style="color: #008080">18</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />                }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">19</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">20</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">21</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> uniqueInstance;<br /> </span><span style="color: #008080">22</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">23</span><span style="color: #000000"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div> <img src ="http://www.aygfsteel.com/sailor/aggbug/216787.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sailor/" target="_blank">sailor</a> 2008-07-23 09:51 <a href="http://www.aygfsteel.com/sailor/articles/216787.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>模式Q四-3Q:抽象工厂(Abstract Factory)模式http://www.aygfsteel.com/sailor/articles/216666.htmlsailorsailorTue, 22 Jul 2008 09:22:00 GMThttp://www.aygfsteel.com/sailor/articles/216666.htmlhttp://www.aygfsteel.com/sailor/comments/216666.htmlhttp://www.aygfsteel.com/sailor/articles/216666.html#Feedback0http://www.aygfsteel.com/sailor/comments/commentRss/216666.htmlhttp://www.aygfsteel.com/sailor/services/trackbacks/216666.html定义
    提供一个接口,用于创徏相关或相依赖对象的家族,而不需要明指定具体类?br />
原则
    依赖抽象Q而不要依赖具体类
    

实用?br />
  1Q一个系l应当不依赖于品类实例被创立,l成Q和表示的细节。这对于所有Ş态的工厂模式都是重要的?

  2Q这个系l的产品有多于一个的产品?/span>?

  3Q?span style="color: #ff0000">同属于同一个品族的品是设计成在一起?/span>的。这一U束必须得在pȝ的设计中体现出来?

角色

       ?. 抽象工厂模式的类囑֮?


  从上囑֏以看出,单工厂模式涉及到以下的角?

   抽象工厂(AbstractFactory)cL接口

   担Qq个角色的是工厂Ҏ模式的核心,它是与应用程序无关的。Q何在模式中创立对象的工厂cdd现这个接口,或承这个类?

   实工厂类 (Conrete Factory)

   担Qq个角色的是与应用程序紧密相关的Q直接在应用E序调用下,创立产品实例的那样一些类?

   抽象产品 (Abstract Product)

   担Qq个角色的类是工厂方法模式所创立的对象的父类Q或它们共同拥有的接口?

   实?(Concrete Product)

   担Qq个角色的类是工厂方法模式所创立的Q何对象所属的cR?/span>


实例

 抽象工厂模式应用于小花果园系l中。三U不同的背景颜色可以区分工厂c,蔬菜c?W一产品?Q和水果cȝcd(W二产品?

sailor 2008-07-22 17:22 发表评论
]]>
模式Q四-2Q:工厂ҎQFactrory MethodQ模?/title><link>http://www.aygfsteel.com/sailor/articles/216546.html</link><dc:creator>sailor</dc:creator><author>sailor</author><pubDate>Tue, 22 Jul 2008 02:49:00 GMT</pubDate><guid>http://www.aygfsteel.com/sailor/articles/216546.html</guid><wfw:comment>http://www.aygfsteel.com/sailor/comments/216546.html</wfw:comment><comments>http://www.aygfsteel.com/sailor/articles/216546.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sailor/comments/commentRss/216546.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sailor/services/trackbacks/216546.html</trackback:ping><description><![CDATA[<p><strong>定义</strong><br /> <br />     定义了一个创建对象的接口Q但由子cd定要实例化的cL哪一个。工厂方法让cL实例化推q到子类?br /> <br /> </p> <strong>原则</strong><br /> <br />     <strong>依赖抽象Q不依赖具体实现Q依赖倒装Q?br /> </strong>            工厂Ҏ使用l承Q把对象的创建委托给子类Q子cd现工厂方法来创徏对象。这个原则说明了不能让高层组件依赖底层组Ӟ而且Q高层组件和底层lg都应该依赖于抽象?br /> <br /> <strong>角色</strong><br /> <br /> <img title="工厂Ҏcd(囄来源见工参考文?)" height="255" alt="工厂Ҏcd" src="http://www.aygfsteel.com/images/blogjava_net/flying/factorymethod.gif" width="487" align="center" border="0" /><br /> 从上囑֏以看出,工厂Ҏ模式涉及C下的角色<br /> <strong><br /> 抽象工厂接口(Creator)</strong> <br />      担Qq个角色的是工厂Ҏ的核心,它是与应用程序无养I创徏的工厂类必须实现该接口?br /> <strong>实工厂类 (Conrete Creator)<br /> </strong>     担Qq个角色的是与应用程序紧密相关的Q直接在E序的调用下创徏具体的品?br /> <strong>产品 (Product) </strong><br />      担Qq个角色的是工厂Ҏ模式所创徏对象的父c,或者是必须实现的接口?br /> <strong>实?(Concrete Product)</strong><br />    担Qq个角色的是工厂Ҏ模式所创徏对象所属的cR?br /> <br />     工厂Ҏ模式和简单工厂模式在定义上的不同是很明显的。工厂方法模式的核心是一个抽象工厂类,而不像简单工厂模? 把核心放在一个实cM。工厂方法模式可以允许很多实的工厂类从抽象工厂类l承下来, 从而可以在实际上成为多个简单工厂模式的l合,从而推q了单工厂模式?br />     反过来讲,单工厂模式是由工厂方法模式退化而来。设惛_果我们非常确定一个系l只需要一个实的工厂类, 那么׃妨把抽象工厂cdq到实的工厂cM厅R而这样一?我们退化到单工厂模式了?<br />    工厂Ҏ模式又叫多Ş性工厂模式,昄是因为实工厂c都有共同的接口Q或者都有共同的抽象父类?br /> <br /> <strong>实例Q??<br /> </strong>    <br /> 参考资料:《First Head 设计模式?br />                     ?a id="viewpost1_TitleUrl" href="http://www.aygfsteel.com/flying/archive/2006/07/12/57731.html">菜鸟学设计模?------工厂Ҏ(Factory Method)模式 </a>?br /> <br /> <br /> <img src ="http://www.aygfsteel.com/sailor/aggbug/216546.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sailor/" target="_blank">sailor</a> 2008-07-22 10:49 <a href="http://www.aygfsteel.com/sailor/articles/216546.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>模式目录http://www.aygfsteel.com/sailor/articles/216544.htmlsailorsailorTue, 22 Jul 2008 02:47:00 GMThttp://www.aygfsteel.com/sailor/articles/216544.htmlhttp://www.aygfsteel.com/sailor/comments/216544.htmlhttp://www.aygfsteel.com/sailor/articles/216544.html#Feedback0http://www.aygfsteel.com/sailor/comments/commentRss/216544.htmlhttp://www.aygfsteel.com/sailor/services/trackbacks/216544.html模式Q一Q:{略QStrategyQ模?/a>

模式Q二Q:观察者(ObserverQ模?/a>

模式Q三Q:装饰者(DecoratorQ模?/a>

模式Q四-1Q:?Simple Factory)工厂模式

模式Q四-2Q:工厂ҎQFactrory MethodQ模?/a>

模式Q四-3Q:抽象工厂(Abstract Factory)模式

模式Q五Q:单gQsingletonQ模?/a>

模式Q六Q:命oQCommandQ模?/a>

模式Q七Q:适配器(AdapterQ模?/a>

模式Q八Q:外观QFacadeQ模?/a>

模式Q九Q:模板ҎQTemplate MethodQ模?/a>

sailor 2008-07-22 10:47 发表评论
]]>
模式Q四-1Q:单工厂(Simple FactoryQ模?/title><link>http://www.aygfsteel.com/sailor/articles/216538.html</link><dc:creator>sailor</dc:creator><author>sailor</author><pubDate>Tue, 22 Jul 2008 02:03:00 GMT</pubDate><guid>http://www.aygfsteel.com/sailor/articles/216538.html</guid><wfw:comment>http://www.aygfsteel.com/sailor/comments/216538.html</wfw:comment><comments>http://www.aygfsteel.com/sailor/articles/216538.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sailor/comments/commentRss/216538.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sailor/services/trackbacks/216538.html</trackback:ping><description><![CDATA[工厂模式是专门负责将大量有共同接口的cd例化,而且不必事先知道每次是要实例化哪一个类的模式?br /> <br /> <strong>一、工厂模式有三种形?/strong>  <br />     单工?Simple Factory)模式 Q又U静态工厂模?br />  工厂Ҏ(Factory Method)模式,又称多Ş性工?Polymorphic Factory)模式 <br />  抽象工厂(Abstract Factory)模式,又称工具?Kit或Toolkit)模式 <br /> <br /> <h4 id="subjcns!924aeffdc9f1325f!135" style="margin-bottom: 0px">二、简单工厂模?/h4> <p style="margin-bottom: 0px">        《Head First 设计模式》认为它不是一个设计模式,更像一U编E习惯,优点是可以将客户端程序从具体cM解耦,不失Z个简单的Ҏ?br /> <br /> <strong>1、定?br />     </strong>单工厂模式是׃个工厂对象决定创建出那一U品类的实例,它是׃个工厂类Ҏ传入的参量决定创建出哪一U品类的实例?<br /> <br /> <strong>2、角?/strong><br />     单工厂模式涉及到工厂角色、抽象角色以及具体品角色等<br />     <br />     工厂c(CreatorQ角Ԍ担Qq个角色的是工厂Ҏ模式的核心,含有与应用紧密相关的商业逻辑。工厂类在客L的直接调用下创徏产品对象Q它往往׃个具体的JAVAcd现?br /> <br />     抽象产品QProductQ角Ԍ担Qq个角色的类是工厂方法模式所创徏的对象的父类Q或他们共同拥有的接口。抽象品角色可以用一个java接口或者Java抽象cd现?br /> <br />     具体产品QConcrete ProductQ角Ԍ工厂Ҏ模式所创徏的Q何对象是q个角色的实例,具体产品角色׃个具体javacd现?br /> <br /> <strong>3、实?br /> <br /> <div align="center"><img style="width: 558px; height: 351px" height="351" alt="" src="C:\simpleFactoryUML.bmp" width="558" border="0" /></div> <br /> </p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080"> 1</span><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">package</span><span style="color: #000000"> com.sailor.simpleFactory;<br /> </span><span style="color: #008080"> 2</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> </span><span style="color: #008080"> 3</span><span style="color: #000000"><img id="Codehighlighter1_65_200_Open_Image" onclick="this.style.display='none'; Codehighlighter1_65_200_Open_Text.style.display='none'; Codehighlighter1_65_200_Closed_Image.style.display='inline'; Codehighlighter1_65_200_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_65_200_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_65_200_Closed_Text.style.display='none'; Codehighlighter1_65_200_Open_Image.style.display='inline'; Codehighlighter1_65_200_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">abstract</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Product </span><span id="Codehighlighter1_65_200_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_65_200_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080"> 4</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080"> 5</span><span style="color: #000000"><img id="Codehighlighter1_90_123_Open_Image" onclick="this.style.display='none'; Codehighlighter1_90_123_Open_Text.style.display='none'; Codehighlighter1_90_123_Closed_Image.style.display='inline'; Codehighlighter1_90_123_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_90_123_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_90_123_Closed_Text.style.display='none'; Codehighlighter1_90_123_Open_Image.style.display='inline'; Codehighlighter1_90_123_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> produce()</span><span id="Codehighlighter1_90_123_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_90_123_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080"> 6</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">生产品</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> </span><span style="color: #008080"> 7</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080"> 8</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    <br /> </span><span style="color: #008080"> 9</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">abstract</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> category();<br /> </span><span style="color: #008080">10</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080">11</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    <br /> </span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">abstract</span><span style="color: #000000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> salePrice();<br /> </span><span style="color: #008080">13</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    <br /> </span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span></div> </strong><br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080"> 1</span><img id="Codehighlighter1_0_10_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_10_Open_Text.style.display='none'; Codehighlighter1_0_10_Closed_Image.style.display='inline'; Codehighlighter1_0_10_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_0_10_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_0_10_Closed_Text.style.display='none'; Codehighlighter1_0_10_Open_Image.style.display='inline'; Codehighlighter1_0_10_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /><span id="Codehighlighter1_0_10_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_0_10_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"><br /> </span><span style="color: #008080"> 2</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * <br /> </span><span style="color: #008080"> 3</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /> </span><span style="color: #008080"> 4</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">package</span><span style="color: #000000"> com.sailor.simpleFactory;<br /> </span><span style="color: #008080"> 5</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> </span><span style="color: #008080"> 6</span><span style="color: #000000"><img id="Codehighlighter1_47_107_Open_Image" onclick="this.style.display='none'; Codehighlighter1_47_107_Open_Text.style.display='none'; Codehighlighter1_47_107_Closed_Image.style.display='inline'; Codehighlighter1_47_107_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_47_107_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_47_107_Closed_Text.style.display='none'; Codehighlighter1_47_107_Open_Image.style.display='inline'; Codehighlighter1_47_107_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span id="Codehighlighter1_47_107_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_47_107_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"><br /> </span><span style="color: #008080"> 7</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * 具体产品<br /> </span><span style="color: #008080"> 8</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * </span><span style="color: #808080">@author</span><span style="color: #008000"> sailor<br /> </span><span style="color: #008080"> 9</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * Jul 22, 2008 10:15:14 AM<br /> </span><span style="color: #008080">10</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">11</span><span style="color: #000000"><img id="Codehighlighter1_141_286_Open_Image" onclick="this.style.display='none'; Codehighlighter1_141_286_Open_Text.style.display='none'; Codehighlighter1_141_286_Closed_Image.style.display='inline'; Codehighlighter1_141_286_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_141_286_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_141_286_Closed_Text.style.display='none'; Codehighlighter1_141_286_Open_Image.style.display='inline'; Codehighlighter1_141_286_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Car </span><span style="color: #0000ff">extends</span><span style="color: #000000"> Product</span><span id="Codehighlighter1_141_286_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_141_286_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080">13</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    @Override<br /> </span><span style="color: #008080">14</span><span style="color: #000000"><img id="Codehighlighter1_179_213_Open_Image" onclick="this.style.display='none'; Codehighlighter1_179_213_Open_Text.style.display='none'; Codehighlighter1_179_213_Closed_Image.style.display='inline'; Codehighlighter1_179_213_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_179_213_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_179_213_Closed_Text.style.display='none'; Codehighlighter1_179_213_Open_Image.style.display='inline'; Codehighlighter1_179_213_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> category() </span><span id="Codehighlighter1_179_213_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_179_213_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">生񔞮汽?/span><span style="color: #000000">"</span><span style="color: #000000">);<br /> </span><span style="color: #008080">16</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">17</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    @Override<br /> </span><span style="color: #008080">19</span><span style="color: #000000"><img id="Codehighlighter1_251_283_Open_Image" onclick="this.style.display='none'; Codehighlighter1_251_283_Open_Text.style.display='none'; Codehighlighter1_251_283_Closed_Image.style.display='inline'; Codehighlighter1_251_283_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_251_283_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_251_283_Closed_Text.style.display='none'; Codehighlighter1_251_283_Open_Image.style.display='inline'; Codehighlighter1_251_283_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> salePrice() </span><span id="Codehighlighter1_251_283_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_251_283_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">20</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Integer(</span><span style="color: #000000">10000</span><span style="color: #000000">);<br /> </span><span style="color: #008080">21</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">22</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080">23</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">24</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span></div> <br /> <br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080"> 1</span><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">package</span><span style="color: #000000"> com.sailor.simpleFactory;<br /> </span><span style="color: #008080"> 2</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> </span><span style="color: #008080"> 3</span><span style="color: #000000"><img id="Codehighlighter1_35_95_Open_Image" onclick="this.style.display='none'; Codehighlighter1_35_95_Open_Text.style.display='none'; Codehighlighter1_35_95_Closed_Image.style.display='inline'; Codehighlighter1_35_95_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_35_95_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_35_95_Closed_Text.style.display='none'; Codehighlighter1_35_95_Open_Image.style.display='inline'; Codehighlighter1_35_95_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span id="Codehighlighter1_35_95_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_35_95_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"><br /> </span><span style="color: #008080"> 4</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * 具体产品<br /> </span><span style="color: #008080"> 5</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * </span><span style="color: #808080">@author</span><span style="color: #008000"> sailor<br /> </span><span style="color: #008080"> 6</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * Jul 22, 2008 10:17:12 AM<br /> </span><span style="color: #008080"> 7</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /> </span><span style="color: #008080"> 8</span><span style="color: #000000"><img id="Codehighlighter1_131_262_Open_Image" onclick="this.style.display='none'; Codehighlighter1_131_262_Open_Text.style.display='none'; Codehighlighter1_131_262_Closed_Image.style.display='inline'; Codehighlighter1_131_262_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_131_262_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_131_262_Closed_Text.style.display='none'; Codehighlighter1_131_262_Open_Image.style.display='inline'; Codehighlighter1_131_262_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Pizza </span><span style="color: #0000ff">extends</span><span style="color: #000000"> Product</span><span id="Codehighlighter1_131_262_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_131_262_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080"> 9</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080">10</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    @Override<br /> </span><span style="color: #008080">11</span><span style="color: #000000"><img id="Codehighlighter1_169_205_Open_Image" onclick="this.style.display='none'; Codehighlighter1_169_205_Open_Text.style.display='none'; Codehighlighter1_169_205_Closed_Image.style.display='inline'; Codehighlighter1_169_205_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_169_205_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_169_205_Closed_Text.style.display='none'; Codehighlighter1_169_205_Open_Image.style.display='inline'; Codehighlighter1_169_205_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> category() </span><span id="Codehighlighter1_169_205_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_169_205_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">生Pizza</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> </span><span style="color: #008080">13</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    @Override<br /> </span><span style="color: #008080">16</span><span style="color: #000000"><img id="Codehighlighter1_243_259_Open_Image" onclick="this.style.display='none'; Codehighlighter1_243_259_Open_Text.style.display='none'; Codehighlighter1_243_259_Closed_Image.style.display='inline'; Codehighlighter1_243_259_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_243_259_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_243_259_Closed_Text.style.display='none'; Codehighlighter1_243_259_Open_Image.style.display='inline'; Codehighlighter1_243_259_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> salePrice() </span><span id="Codehighlighter1_243_259_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_243_259_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">17</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #000000">20</span><span style="color: #000000">;<br /> </span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">19</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080">20</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span></div> <br /> <br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080"> 1</span><img id="Codehighlighter1_0_58_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_58_Open_Text.style.display='none'; Codehighlighter1_0_58_Closed_Image.style.display='inline'; Codehighlighter1_0_58_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_0_58_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_0_58_Closed_Text.style.display='none'; Codehighlighter1_0_58_Open_Image.style.display='inline'; Codehighlighter1_0_58_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /><span id="Codehighlighter1_0_58_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_0_58_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"><br /> </span><span style="color: #008080"> 2</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * 工厂<br /> </span><span style="color: #008080"> 3</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * </span><span style="color: #808080">@author</span><span style="color: #008000"> sailor<br /> </span><span style="color: #008080"> 4</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * Jul 22, 2008 10:13:23 AM<br /> </span><span style="color: #008080"> 5</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /> </span><span style="color: #008080"> 6</span><span style="color: #000000"><img id="Codehighlighter1_87_277_Open_Image" onclick="this.style.display='none'; Codehighlighter1_87_277_Open_Text.style.display='none'; Codehighlighter1_87_277_Closed_Image.style.display='inline'; Codehighlighter1_87_277_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_87_277_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_87_277_Closed_Text.style.display='none'; Codehighlighter1_87_277_Open_Image.style.display='inline'; Codehighlighter1_87_277_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> SimpleFactory </span><span id="Codehighlighter1_87_277_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_87_277_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080"> 7</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080"> 8</span><span style="color: #000000"><img id="Codehighlighter1_142_275_Open_Image" onclick="this.style.display='none'; Codehighlighter1_142_275_Open_Text.style.display='none'; Codehighlighter1_142_275_Closed_Image.style.display='inline'; Codehighlighter1_142_275_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_142_275_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_142_275_Closed_Text.style.display='none'; Codehighlighter1_142_275_Open_Image.style.display='inline'; Codehighlighter1_142_275_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> Product createProduct(String product)</span><span id="Codehighlighter1_142_275_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_142_275_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080"> 9</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">"</span><span style="color: #000000">car</span><span style="color: #000000">"</span><span style="color: #000000">.equals(product))<br /> </span><span style="color: #008080">10</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Car();<br /> </span><span style="color: #008080">11</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">else</span><span style="color: #000000"> </span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">"</span><span style="color: #000000">pizza</span><span style="color: #000000">"</span><span style="color: #000000">.equals(product))<br /> </span><span style="color: #008080">12</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Pizza();<br /> </span><span style="color: #008080">13</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">else</span><span style="color: #000000"><br /> </span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">;<br /> </span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">16</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span></div> <br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080"> 1</span><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">package</span><span style="color: #000000"> com.sailor.simpleFactory;<br /> </span><span style="color: #008080"> 2</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> </span><span style="color: #008080"> 3</span><span style="color: #000000"><img id="Codehighlighter1_35_94_Open_Image" onclick="this.style.display='none'; Codehighlighter1_35_94_Open_Text.style.display='none'; Codehighlighter1_35_94_Closed_Image.style.display='inline'; Codehighlighter1_35_94_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_35_94_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_35_94_Closed_Text.style.display='none'; Codehighlighter1_35_94_Open_Image.style.display='inline'; Codehighlighter1_35_94_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span id="Codehighlighter1_35_94_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_35_94_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"><br /> </span><span style="color: #008080"> 4</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * 客户?br /> </span><span style="color: #008080"> 5</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * </span><span style="color: #808080">@author</span><span style="color: #008000"> sailor<br /> </span><span style="color: #008080"> 6</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * Jul 22, 2008 10:20:59 AM<br /> </span><span style="color: #008080"> 7</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /> </span><span style="color: #008080"> 8</span><span style="color: #000000"><img id="Codehighlighter1_116_515_Open_Image" onclick="this.style.display='none'; Codehighlighter1_116_515_Open_Text.style.display='none'; Codehighlighter1_116_515_Closed_Image.style.display='inline'; Codehighlighter1_116_515_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_116_515_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_116_515_Closed_Text.style.display='none'; Codehighlighter1_116_515_Open_Image.style.display='inline'; Codehighlighter1_116_515_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Client </span><span id="Codehighlighter1_116_515_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_116_515_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080"> 9</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080">10</span><span style="color: #000000"><img id="Codehighlighter1_120_143_Open_Image" onclick="this.style.display='none'; Codehighlighter1_120_143_Open_Text.style.display='none'; Codehighlighter1_120_143_Closed_Image.style.display='inline'; Codehighlighter1_120_143_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_120_143_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_120_143_Closed_Text.style.display='none'; Codehighlighter1_120_143_Open_Image.style.display='inline'; Codehighlighter1_120_143_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span id="Codehighlighter1_120_143_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_120_143_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"><br /> </span><span style="color: #008080">11</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />     * </span><span style="color: #808080">@param</span><span style="color: #008000"> args<br /> </span><span style="color: #008080">12</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />     </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">13</span><span style="color: #000000"><img id="Codehighlighter1_185_513_Open_Image" onclick="this.style.display='none'; Codehighlighter1_185_513_Open_Text.style.display='none'; Codehighlighter1_185_513_Closed_Image.style.display='inline'; Codehighlighter1_185_513_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_185_513_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_185_513_Closed_Text.style.display='none'; Codehighlighter1_185_513_Open_Image.style.display='inline'; Codehighlighter1_185_513_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String[] args) </span><span id="Codehighlighter1_185_513_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_185_513_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        <br /> </span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        Product product1 </span><span style="color: #000000">=</span><span style="color: #000000"> SimpleFactory.createProduct(</span><span style="color: #000000">"</span><span style="color: #000000">car</span><span style="color: #000000">"</span><span style="color: #000000">);    <br /> </span><span style="color: #008080">16</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        product1.category();<br /> </span><span style="color: #008080">17</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        product1.produce();<br /> </span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">销售额Q?nbsp;</span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> product1.salePrice());<br /> </span><span style="color: #008080">19</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        <br /> </span><span style="color: #008080">20</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        <br /> </span><span style="color: #008080">21</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        Product product2 </span><span style="color: #000000">=</span><span style="color: #000000"> SimpleFactory.createProduct(</span><span style="color: #000000">"</span><span style="color: #000000">pizza</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> </span><span style="color: #008080">22</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        product2.category();<br /> </span><span style="color: #008080">23</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        product2.produce();<br /> </span><span style="color: #008080">24</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">销售额Q?nbsp;</span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> product2.salePrice());    <br /> </span><span style="color: #008080">25</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">26</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span></div> <img src ="http://www.aygfsteel.com/sailor/aggbug/216538.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sailor/" target="_blank">sailor</a> 2008-07-22 10:03 <a href="http://www.aygfsteel.com/sailor/articles/216538.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>模式Q三Q:装饰者(decoratorQ模?/title><link>http://www.aygfsteel.com/sailor/articles/216326.html</link><dc:creator>sailor</dc:creator><author>sailor</author><pubDate>Mon, 21 Jul 2008 04:15:00 GMT</pubDate><guid>http://www.aygfsteel.com/sailor/articles/216326.html</guid><wfw:comment>http://www.aygfsteel.com/sailor/comments/216326.html</wfw:comment><comments>http://www.aygfsteel.com/sailor/articles/216326.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sailor/comments/commentRss/216326.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sailor/services/trackbacks/216326.html</trackback:ping><description><![CDATA[<strong>1、定?br /> </strong>    动态地责任附加到对象上。若要扩展功能,装饰着提供了比l承者更有弹性的替代Ҏ?br /> <br /> <strong>2、原?/strong><br />     <strong>Z互对象之间的耦合设计而努?br /> </strong>    <strong>Ҏ展开放,对修改关?br /> </strong><br /> <strong>3、适用环境</strong><br />     在不影响其他对象的情况下Q以动态、透明的方式给单个对象d职责?br />     处理那些可以撤消的职责?br />     当不能采用生成子cȝҎq行扩充时。一U情冉|Q可能有大量独立的扩展,为支持每一U组合将产生大量的子c,使得子类数目呈爆炸性增ѝ另一U情况可能是因ؓcd义被隐藏Q或cd义不能用于生成子cR?br /> <br /> <strong>4、本模式中的角色</strong><br /> <p><strong>    抽象构g(Component):</strong>l出一个抽象接口,以规范准备接攉加责ȝ对象?br /> <strong>    具体构g(Concrete Component)Q?/strong>定义一个接收到附加责Q的类?br /> <strong>    装饰QDecoratorQ?</strong>持有一个构件对象的实例Qƈ定义与抽象构件一致的接口?br /> <strong>    具体装饰QConcrete DecoratorQ?</strong>负责l构件对象脓上附加的责Q?br /> </p> <div align="center"> <div align="center"><img height="307" alt="Decorator.jpg" src="http://www.aygfsteel.com/images/blogjava_net/flying/Decorator.jpg" width="631" border="0" />Q图例)<br /> </div> </div> <br /> <br /> 具体例子Q?br /> 先定义抽象构Ӟ<br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">package</span><span style="color: #000000"> decorator;<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #008000">//</span><span style="color: #008000">抽象构g接口</span><span style="color: #008000"><br /> <img id="Codehighlighter1_54_88_Open_Image" onclick="this.style.display='none'; Codehighlighter1_54_88_Open_Text.style.display='none'; Codehighlighter1_54_88_Closed_Image.style.display='inline'; Codehighlighter1_54_88_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_54_88_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_54_88_Closed_Text.style.display='none'; Codehighlighter1_54_88_Open_Image.style.display='inline'; Codehighlighter1_54_88_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">interface</span><span style="color: #000000"> Component</span><span id="Codehighlighter1_54_88_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_54_88_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> sampleOperation();<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div> <br /> 一个具体构?---门:<br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">package</span><span style="color: #000000"> decorator;<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #008000">//</span><span style="color: #008000">具体构g-----?/span><span style="color: #008000"><br /> <img id="Codehighlighter1_71_154_Open_Image" onclick="this.style.display='none'; Codehighlighter1_71_154_Open_Text.style.display='none'; Codehighlighter1_71_154_Closed_Image.style.display='inline'; Codehighlighter1_71_154_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_71_154_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_71_154_Closed_Text.style.display='none'; Codehighlighter1_71_154_Open_Image.style.display='inline'; Codehighlighter1_71_154_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000">  Door </span><span style="color: #0000ff">implements</span><span style="color: #000000"> Component</span><span id="Codehighlighter1_71_154_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_71_154_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #008000">//</span><span style="color: #008000">实现Ҏ</span><span style="color: #008000"><br /> <img id="Codehighlighter1_111_152_Open_Image" onclick="this.style.display='none'; Codehighlighter1_111_152_Open_Text.style.display='none'; Codehighlighter1_111_152_Closed_Image.style.display='inline'; Codehighlighter1_111_152_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_111_152_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_111_152_Closed_Text.style.display='none'; Codehighlighter1_111_152_Open_Image.style.display='inline'; Codehighlighter1_111_152_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span style="color: #000000">    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> sampleOperation()</span><span id="Codehighlighter1_111_152_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_111_152_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">build a door</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div> <br /> 装饰(抽象c?Q?br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">package</span><span style="color: #000000"> decorator;<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" /><br /> <img id="Codehighlighter1_72_276_Open_Image" onclick="this.style.display='none'; Codehighlighter1_72_276_Open_Text.style.display='none'; Codehighlighter1_72_276_Closed_Image.style.display='inline'; Codehighlighter1_72_276_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_72_276_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_72_276_Closed_Text.style.display='none'; Codehighlighter1_72_276_Open_Image.style.display='inline'; Codehighlighter1_72_276_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">abstract</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Decorator </span><span style="color: #0000ff">implements</span><span style="color: #000000"> Component</span><span id="Codehighlighter1_72_276_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_72_276_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #008000">//</span><span style="color: #008000">持有一个构件对象的实例</span><span style="color: #008000"><br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">    </span><span style="color: #0000ff">private</span><span style="color: #000000"> Component component;<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #008000">//</span><span style="color: #008000">构造方?/span><span style="color: #008000"><br /> <img id="Codehighlighter1_165_196_Open_Image" onclick="this.style.display='none'; Codehighlighter1_165_196_Open_Text.style.display='none'; Codehighlighter1_165_196_Closed_Image.style.display='inline'; Codehighlighter1_165_196_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_165_196_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_165_196_Closed_Text.style.display='none'; Codehighlighter1_165_196_Open_Image.style.display='inline'; Codehighlighter1_165_196_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span style="color: #000000">    </span><span style="color: #0000ff">public</span><span style="color: #000000"> Decorator(Component component)</span><span id="Codehighlighter1_165_196_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_165_196_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #0000ff">this</span><span style="color: #000000">.component</span><span style="color: #000000">=</span><span style="color: #000000">component;<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #008000">//</span><span style="color: #008000">Ҏ的具体实?/span><span style="color: #008000"><br /> <img id="Codehighlighter1_240_274_Open_Image" onclick="this.style.display='none'; Codehighlighter1_240_274_Open_Text.style.display='none'; Codehighlighter1_240_274_Closed_Image.style.display='inline'; Codehighlighter1_240_274_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_240_274_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_240_274_Closed_Text.style.display='none'; Codehighlighter1_240_274_Open_Image.style.display='inline'; Codehighlighter1_240_274_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span style="color: #000000">    </span><span style="color: #0000ff">public</span><span style="color: #000000">  </span><span style="color: #0000ff">void</span><span style="color: #000000"> sampleOperation()</span><span id="Codehighlighter1_240_274_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_240_274_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />        component.sampleOperation();<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div> <br /> 具体装饰Q?br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">package</span><span style="color: #000000"> decorator;<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #008000">//</span><span style="color: #008000">具体装饰----把手</span><span style="color: #008000"><br /> <img id="Codehighlighter1_67_240_Open_Image" onclick="this.style.display='none'; Codehighlighter1_67_240_Open_Text.style.display='none'; Codehighlighter1_67_240_Closed_Image.style.display='inline'; Codehighlighter1_67_240_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_67_240_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_67_240_Closed_Text.style.display='none'; Codehighlighter1_67_240_Open_Image.style.display='inline'; Codehighlighter1_67_240_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Knob </span><span style="color: #0000ff">extends</span><span style="color: #000000"> Decorator</span><span id="Codehighlighter1_67_240_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_67_240_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" /><br /> <img id="Codehighlighter1_103_126_Open_Image" onclick="this.style.display='none'; Codehighlighter1_103_126_Open_Text.style.display='none'; Codehighlighter1_103_126_Closed_Image.style.display='inline'; Codehighlighter1_103_126_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_103_126_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_103_126_Closed_Text.style.display='none'; Codehighlighter1_103_126_Open_Image.style.display='inline'; Codehighlighter1_103_126_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> Knob(Component component)</span><span id="Codehighlighter1_103_126_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_103_126_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #0000ff">super</span><span style="color: #000000">(component);<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />    <br /> <img id="Codehighlighter1_160_238_Open_Image" onclick="this.style.display='none'; Codehighlighter1_160_238_Open_Text.style.display='none'; Codehighlighter1_160_238_Closed_Image.style.display='inline'; Codehighlighter1_160_238_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_160_238_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_160_238_Closed_Text.style.display='none'; Codehighlighter1_160_238_Open_Image.style.display='inline'; Codehighlighter1_160_238_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> sampleOperation()</span><span id="Codehighlighter1_160_238_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_160_238_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #0000ff">super</span><span style="color: #000000">.sampleOperation();<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #008000">//</span><span style="color: #008000">附加?责Q"</span><span style="color: #008000"><br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">add a knob</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">package</span><span style="color: #000000"> decorator;<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #008000">//</span><span style="color: #008000">具体装饰----?/span><span style="color: #008000"><br /> <img id="Codehighlighter1_66_236_Open_Image" onclick="this.style.display='none'; Codehighlighter1_66_236_Open_Text.style.display='none'; Codehighlighter1_66_236_Closed_Image.style.display='inline'; Codehighlighter1_66_236_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_66_236_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_66_236_Closed_Text.style.display='none'; Codehighlighter1_66_236_Open_Image.style.display='inline'; Codehighlighter1_66_236_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> Lock </span><span style="color: #0000ff">extends</span><span style="color: #000000"> Decorator</span><span id="Codehighlighter1_66_236_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_66_236_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" /><br /> <img id="Codehighlighter1_102_125_Open_Image" onclick="this.style.display='none'; Codehighlighter1_102_125_Open_Text.style.display='none'; Codehighlighter1_102_125_Closed_Image.style.display='inline'; Codehighlighter1_102_125_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_102_125_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_102_125_Closed_Text.style.display='none'; Codehighlighter1_102_125_Open_Image.style.display='inline'; Codehighlighter1_102_125_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> Lock(Component component)</span><span id="Codehighlighter1_102_125_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_102_125_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #0000ff">super</span><span style="color: #000000">(component);<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /> <img id="Codehighlighter1_157_234_Open_Image" onclick="this.style.display='none'; Codehighlighter1_157_234_Open_Text.style.display='none'; Codehighlighter1_157_234_Closed_Image.style.display='inline'; Codehighlighter1_157_234_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_157_234_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_157_234_Closed_Text.style.display='none'; Codehighlighter1_157_234_Open_Image.style.display='inline'; Codehighlighter1_157_234_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> sampleOperation()</span><span id="Codehighlighter1_157_234_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_157_234_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #0000ff">super</span><span style="color: #000000">.sampleOperation();<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #008000">//</span><span style="color: #008000">附加"责Q"</span><span style="color: #008000"><br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">add a lock</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div> q行c:<br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">package</span><span style="color: #000000"> decorator;<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/None.gif" align="top" /><br /> <img id="Codehighlighter1_49_216_Open_Image" onclick="this.style.display='none'; Codehighlighter1_49_216_Open_Text.style.display='none'; Codehighlighter1_49_216_Closed_Image.style.display='inline'; Codehighlighter1_49_216_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_49_216_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_49_216_Closed_Text.style.display='none'; Codehighlighter1_49_216_Open_Image.style.display='inline'; Codehighlighter1_49_216_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> DecoratorPattern</span><span id="Codehighlighter1_49_216_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_49_216_Open_Text"><span style="color: #000000">{<br /> <img id="Codehighlighter1_90_214_Open_Image" onclick="this.style.display='none'; Codehighlighter1_90_214_Open_Text.style.display='none'; Codehighlighter1_90_214_Closed_Image.style.display='inline'; Codehighlighter1_90_214_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_90_214_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_90_214_Closed_Text.style.display='none'; Codehighlighter1_90_214_Open_Image.style.display='inline'; Codehighlighter1_90_214_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String[] args)</span><span id="Codehighlighter1_90_214_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_90_214_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />        Component door</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> Door();<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />        Component lock</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> Lock(door);<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />        Component knob</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> Knob(lock);<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/InBlock.gif" align="top" />        knob.sampleOperation();<br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div> <br /> q行l果Q?br /> <font color="#008000">build a door<br /> add a lock<br /> add a knob<br /> Press any key to continue...<br /> </font><br /> 参考资料:《Head First 设计模式?br />                     <a id="viewpost1_TitleUrl" href="http://www.aygfsteel.com/flying/archive/2006/08/14/63376.html">设计模式学习W记Q十Q?-------装饰(Decorator)模式</a> <img src ="http://www.aygfsteel.com/sailor/aggbug/216326.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sailor/" target="_blank">sailor</a> 2008-07-21 12:15 <a href="http://www.aygfsteel.com/sailor/articles/216326.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>模式Q二Q:观察者(ObserverQ模?/title><link>http://www.aygfsteel.com/sailor/articles/216030.html</link><dc:creator>sailor</dc:creator><author>sailor</author><pubDate>Sat, 19 Jul 2008 06:58:00 GMT</pubDate><guid>http://www.aygfsteel.com/sailor/articles/216030.html</guid><wfw:comment>http://www.aygfsteel.com/sailor/comments/216030.html</wfw:comment><comments>http://www.aygfsteel.com/sailor/articles/216030.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sailor/comments/commentRss/216030.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sailor/services/trackbacks/216030.html</trackback:ping><description><![CDATA[1、定?br /> <br />     在对象之间定义一对多的依赖,q样一来,当一个对象改变时状态,依赖他的对象会收到通知Qƈ自动更新。这U模式以松耦合方式在一些列对象之间改变状态。MVC模式是观察者模式的一个代表?br /> <br /> 2、实用?br /> <br />     当一个抽象模型有两个斚w, 其中一个方面依赖于另一斚w。将q二者封装在独立的对象中以它们可以各自独立地改变和复用?nbsp;<br />     当对一个对象的改变需要同时改变其它对? 而不知道具体有多对象有待改变?br />     当一个对象必通知其它对象Q而它又不能假定其它对象是谁。换a? 你不希望q些对象是紧密耦合的?br />   <p>3、设计原?br /> <br /> <span style="color: #cc99ff"><span style="color: #000000">    <strong>扑ևE序中会变化的方面,然后其和固定不变的斚w相分?/strong></span><br /> </span>        在观察者模式中Q会改变的是主题的状态,以及观察者的数目和类型。用q个模式Q你可以依赖于主题状态的对象Q却不必改变主题。这叫提前规划?br /> <br />     <span style="color: #000000"><strong>针对接口~程Q不针对实现~程</strong></span><br />         主题与观察者都使用接口Q观察者利用主题的接口Q向主题注册Q而主题利用观察者的接口通知接口。这样可以让两者之间运作正常,又同事具有松耦合的优炏V?br /> <br /> <span style="color: #000000">    <strong>多用l合Q少用?/strong></span><br />         观察者模式利?#8220;l合”Q将许多观察者组合进主题中。对象之间的q种关系不是通过l承产生的,而是在运行时利用l合的方式而生的?br />  <br /> 4、实?br />    <br /> <div align="center"><img style="border-left-color: #000000; border-bottom-color: #000000; border-top-color: #000000; border-right-color: #000000" height="275" alt="" src="E:\Project\模式\obverser\UML.BMP" width="562" border="1" /></div> <br /> </p> <img src ="http://www.aygfsteel.com/sailor/aggbug/216030.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sailor/" target="_blank">sailor</a> 2008-07-19 14:58 <a href="http://www.aygfsteel.com/sailor/articles/216030.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>模式Q一Q:{略QStrategyQ模?/title><link>http://www.aygfsteel.com/sailor/articles/216027.html</link><dc:creator>sailor</dc:creator><author>sailor</author><pubDate>Sat, 19 Jul 2008 06:53:00 GMT</pubDate><guid>http://www.aygfsteel.com/sailor/articles/216027.html</guid><wfw:comment>http://www.aygfsteel.com/sailor/comments/216027.html</wfw:comment><comments>http://www.aygfsteel.com/sailor/articles/216027.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sailor/comments/commentRss/216027.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sailor/services/trackbacks/216027.html</trackback:ping><description><![CDATA[    定义Q定义了法族,分别装hQ让他们之间可以怺交换Q此模拟法的变化独立于使用法的客戗?br />     <br />     设计原则Q?br />         1、多用组合,用l承Q?br />         2、针Ҏ口编E,而不是针对实现编E;<br /> <br />      实现Q?br /> <br /> <img height="204" alt="" src="http://www.cnblogs.com/images/cnblogs_com/justinw/str_8.jpg" width="554" border="0" /><br />    <span style="font-size: 10pt">     Context(<span>应用场景):</span> </span> <p style="margin: 0cm 0cm 0pt 42.75pt; text-indent: -21pt"><span style="font-size: 10pt"><span style="color: black; font-family: Wingdings">l<span style="font: 7pt 'Times New Roman'; font-size-adjust: none; font-stretch: normal">         </span></span><span style="color: black; font-family: 宋体">需要?/span><span style="color: black">ConcreteStrategy</span><span style="color: black; font-family: 宋体">提供的算法?/span></span></p> <p style="margin: 0cm 0cm 0pt 42.75pt; text-indent: -21pt"><span style="font-size: 10pt"><span style="color: black; font-family: Wingdings">l<span style="font: 7pt 'Times New Roman'; font-size-adjust: none; font-stretch: normal">         </span></span><span style="color: black; font-family: 宋体">内部l护一?/span><span style="color: black">Strategy</span><span style="color: black; font-family: 宋体">的实例?/span></span></p> <p style="margin: 0cm 0cm 0pt 42.75pt; text-indent: -21pt"><span style="font-size: 10pt"><span style="color: black; font-family: Wingdings">l<span style="font: 7pt 'Times New Roman'; font-size-adjust: none; font-stretch: normal">         </span></span><span style="color: black; font-family: 宋体">负责动态设|运行时</span><span style="color: black">Strategy</span><span style="color: black; font-family: 宋体">具体的实现算法?/span></span></p> <p style="margin: 0cm 0cm 0pt 42.75pt; text-indent: -21pt"><span style="font-size: 10pt"><span style="color: black; font-family: Wingdings">l<span style="font: 7pt 'Times New Roman'; font-size-adjust: none; font-stretch: normal">         </span></span><span style="color: black; font-family: 宋体">负责?/span><span style="color: black">Strategy</span><span style="color: black; font-family: 宋体">之间的交互和数据传递?br /> </span></span></p> <p style="margin: 0cm 0cm 0pt"><span style="font-size: 10pt"><span><br />         Strategy(抽象{略c?Q?/span></span></p> <p style="margin: 0cm 0cm 0pt 42.75pt; text-indent: -21pt"><span style="font-size: 10pt"><span style="color: black; font-family: Wingdings">l<span style="font: 7pt 'Times New Roman'; font-size-adjust: none; font-stretch: normal">         </span></span><span style="color: black; font-family: 宋体">定义了一个公共接口,各种不同的算法以不同的方式实现这个接口,</span><span style="color: black">Context</span><span style="color: black; font-family: 宋体">使用q个接口调用不同的算法,一般用接口或抽象cd现?/span></span></p> <p style="margin: 0cm 0cm 0pt"><span style="font-size: 10pt"><span>        <br />         ConcreteStrategy(具体{略c?Q?/span></span></p> <p style="margin: 0cm 0cm 0pt 42.75pt; text-indent: -21pt"><span style="font-size: 10pt"><span style="color: black; font-family: Wingdings">l<span style="font: 7pt 'Times New Roman'; font-size-adjust: none; font-stretch: normal">         </span></span><span style="color: black; font-family: 宋体">实现?/span><span style="color: black">Strategy</span></span><span style="color: black; font-family: 宋体"><span style="font-size: 10pt">定义的接口,提供具体的算法实现?br /> </span><br /> </span></p> <hr /> <br /> <br />     参考资料:《Head First设计模式?br />                         <a >?span style="font-family: 宋体">鸭子</span><span lang="EN-US">-</span><span style="font-family: 宋体">{略模式Q?/span><span lang="EN-US">Strategy</span><span style="font-family: 宋体">Q?/span>?/a> <img src ="http://www.aygfsteel.com/sailor/aggbug/216027.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sailor/" target="_blank">sailor</a> 2008-07-19 14:53 <a href="http://www.aygfsteel.com/sailor/articles/216027.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank">Խ</a>| <a href="http://" target="_blank">̨</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɶ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">˳</a>| <a href="http://" target="_blank">Զ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ľ</a>| <a href="http://" target="_blank">Ƽ</a>| <a href="http://" target="_blank">ͭ</a>| <a href="http://" target="_blank">Դ</a>| <a href="http://" target="_blank">Ϳ</a>| <a href="http://" target="_blank">ӱʡ</a>| <a href="http://" target="_blank">ʡ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ұ</a>| <a href="http://" target="_blank">ҵ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ӱ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ʦ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">㽭ʡ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">¹Ȫ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>