﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-午夜拍键惊奇-随笔分类-Design Patterns</title><link>http://www.blogjava.net/fidodido/category/2509.html</link><description>子夜 编程 代码与我同在</description><language>zh-cn</language><lastBuildDate>Tue, 27 Feb 2007 10:47:35 GMT</lastBuildDate><pubDate>Tue, 27 Feb 2007 10:47:35 GMT</pubDate><ttl>60</ttl><item><title>缺省适配器模式（Default Adapter）</title><link>http://www.blogjava.net/fidodido/archive/2005/09/06/12197.html</link><dc:creator>^ Mustang ^</dc:creator><author>^ Mustang ^</author><pubDate>Tue, 06 Sep 2005 04:01:00 GMT</pubDate><guid>http://www.blogjava.net/fidodido/archive/2005/09/06/12197.html</guid><wfw:comment>http://www.blogjava.net/fidodido/comments/12197.html</wfw:comment><comments>http://www.blogjava.net/fidodido/archive/2005/09/06/12197.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/fidodido/comments/commentRss/12197.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/fidodido/services/trackbacks/12197.html</trackback:ping><description><![CDATA[<H4>一、概述</H4>
<P>当不需要全部实现适配器接口提供的方法时，可先设计一个抽象类实现适配器接口，并为接口中每个方法提供一个默认实现（空方法）。那么该抽象类的子类可有选择地覆盖父类的某些方法来实现需求。</P>
<H4>二、结构</H4>
<P align=center><IMG height=243 alt=defaultadapter.png src="http://www.blogjava.net/images/blogjava_net/fidodido/2507/defaultadapter.png" width=138 border=0></P>
<H4>&nbsp;</H4>
<H4>三、动机</H4>
<P>对于一个接口不想使用其所有的方法时。</P><img src ="http://www.blogjava.net/fidodido/aggbug/12197.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/fidodido/" target="_blank">^ Mustang ^</a> 2005-09-06 12:01 <a href="http://www.blogjava.net/fidodido/archive/2005/09/06/12197.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>A beginners guide to Dependency Injection [转载自TSS]</title><link>http://www.blogjava.net/fidodido/archive/2005/08/08/9610.html</link><dc:creator>^ Mustang ^</dc:creator><author>^ Mustang ^</author><pubDate>Mon, 08 Aug 2005 14:30:00 GMT</pubDate><guid>http://www.blogjava.net/fidodido/archive/2005/08/08/9610.html</guid><wfw:comment>http://www.blogjava.net/fidodido/comments/9610.html</wfw:comment><comments>http://www.blogjava.net/fidodido/archive/2005/08/08/9610.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/fidodido/comments/commentRss/9610.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/fidodido/services/trackbacks/9610.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: ScopeThis article presents a high level overview of Dependency Injection (DI). It aims to present the overall concept of Dependency Injection to the junior developer within the context of how it cou...&nbsp;&nbsp;<a href='http://www.blogjava.net/fidodido/archive/2005/08/08/9610.html'>阅读全文</a><img src ="http://www.blogjava.net/fidodido/aggbug/9610.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/fidodido/" target="_blank">^ Mustang ^</a> 2005-08-08 22:30 <a href="http://www.blogjava.net/fidodido/archive/2005/08/08/9610.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>适配器模式（Adapter）</title><link>http://www.blogjava.net/fidodido/archive/2005/08/06/9484.html</link><dc:creator>^ Mustang ^</dc:creator><author>^ Mustang ^</author><pubDate>Sat, 06 Aug 2005 11:39:00 GMT</pubDate><guid>http://www.blogjava.net/fidodido/archive/2005/08/06/9484.html</guid><wfw:comment>http://www.blogjava.net/fidodido/comments/9484.html</wfw:comment><comments>http://www.blogjava.net/fidodido/archive/2005/08/06/9484.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/fidodido/comments/commentRss/9484.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/fidodido/services/trackbacks/9484.html</trackback:ping><description><![CDATA[<H3>一、概述</H3>
<P>类的适配器模式把被适配的类的API转换成为目标类的API</P>
<P></P>
<H3>二、结构</H3>
<H4>1、类的适配器模式</H4>
<P align=center><IMG height=187 alt=o_adapter1.gif src="http://www.blogjava.net/images/blogjava_net/fidodido/2507/o_adapter1.gif" width=257 border=0></P>
<P>Target：所期待得到的接口</P>
<P>Adaptee：现有需要适配的类</P>
<P>Adapter：把源接口转化成目标接口的核心类</P>
<P></P>
<H4>2、对象的适配器模式</H4>
<P align=center><IMG height=199 alt=o_adapter2.gif src="http://www.blogjava.net/images/blogjava_net/fidodido/2507/o_adapter2.gif" width=257 border=0></P>
<P>i、同一个适配器可以把源和其子类都适配到目标接口</P>
<P>ii、与类的适配器相比，要覆盖源类的方法不很容易，除非做一个源类的子类，然后对子类适配</P>
<P>iii、可以很方便地添加一个方法</P>
<P></P>
<H3>三、动机</H3>
<P>1、系统需要使用现有的类，而该类的接口不符合系统新的需要</P>
<P>2、需要建立一个可复用的类用于使一些彼此之间没有太大关系的类一同工作</P>
<P>3、需要改变多个已有的子类的接口</P><img src ="http://www.blogjava.net/fidodido/aggbug/9484.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/fidodido/" target="_blank">^ Mustang ^</a> 2005-08-06 19:39 <a href="http://www.blogjava.net/fidodido/archive/2005/08/06/9484.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>原型模式（Prototype）</title><link>http://www.blogjava.net/fidodido/archive/2005/08/05/9376.html</link><dc:creator>^ Mustang ^</dc:creator><author>^ Mustang ^</author><pubDate>Fri, 05 Aug 2005 02:54:00 GMT</pubDate><guid>http://www.blogjava.net/fidodido/archive/2005/08/05/9376.html</guid><wfw:comment>http://www.blogjava.net/fidodido/comments/9376.html</wfw:comment><comments>http://www.blogjava.net/fidodido/archive/2005/08/05/9376.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/fidodido/comments/commentRss/9376.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/fidodido/services/trackbacks/9376.html</trackback:ping><description><![CDATA[<H3>一、概述</H3>
<P><FONT size=2>原型模式属于对象创建模式，通过给出一个原型对象来指明所要创建的对象类型，然后用复制这个对象的方法创建出更多同类型的对象。<BR></FONT></P>
<P></P>
<H4>&nbsp;</H4>
<H3>二、结构</H3>
<H4>1、简单形式</H4>
<P align=center><IMG height=168 alt=o_prototype1.gif src="http://www.blogjava.net/images/blogjava_net/fidodido/2507/o_prototype1.gif" width=314 border=0></P>
<P><FONT size=2>Client：提出创建对象的请求</FONT></P>
<P><FONT size=2>Prototype：抽象角色，给出所有具体原型类所需的接口</FONT></P>
<P><FONT size=2>ConcretePrototype：被复制的对象<BR></FONT></P>
<P></P>
<H4><BR>2、登记形式</H4>
<P align=center><IMG height=227 alt=o_prototype2.gif src="http://www.blogjava.net/images/blogjava_net/fidodido/2507/o_prototype2.gif" width=326 border=0></P>
<P><FONT size=2>PrototypeManager：创建并记录具体对象<BR></FONT></P>
<P></P>
<H4>&nbsp;</H4>
<H3>三、浅克隆与深克隆</H3>
<P><FONT size=2>浅克隆：仅做refrence一级的克隆，refrence所指的对象不被克隆</FONT></P>
<P><FONT size=2>深克隆：将refrence所指的对象进行递归克隆，需考虑克隆深度及循环克隆问题</FONT></P>
<P></P>
<H3><BR>四、动机</H3>
<P><FONT size=2>替换较复杂的等级结构的工厂方法</FONT></P>
<P></P>
<H3><BR>五、优缺点</H3>
<P><FONT color=#000000 size=2><FONT color=#9acd32>1、</FONT>允许动态地增加或减少产品类，且对整个现有的产品结构没有影响</FONT></P>
<P><FONT color=#000000 size=2><FONT color=#9acd32>2、</FONT>提供简化的创建结构</FONT></P>
<P><FONT color=#000000 size=2><FONT color=#9acd32>3、</FONT>具有动态加载新功能的能力</FONT></P>
<P><FONT color=#000000 size=2><FONT color=#9acd32>4、</FONT>产品类不需要有确定的等级结构</FONT></P>
<P><FONT color=#000000 size=2><FONT color=#ffa500>I、</FONT>每一个类必须配备一个克隆方法</FONT></P><img src ="http://www.blogjava.net/fidodido/aggbug/9376.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/fidodido/" target="_blank">^ Mustang ^</a> 2005-08-05 10:54 <a href="http://www.blogjava.net/fidodido/archive/2005/08/05/9376.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用策略模式（Strategy）实现多关键字排序</title><link>http://www.blogjava.net/fidodido/archive/2005/08/04/9181.html</link><dc:creator>^ Mustang ^</dc:creator><author>^ Mustang ^</author><pubDate>Thu, 04 Aug 2005 04:37:00 GMT</pubDate><guid>http://www.blogjava.net/fidodido/archive/2005/08/04/9181.html</guid><wfw:comment>http://www.blogjava.net/fidodido/comments/9181.html</wfw:comment><comments>http://www.blogjava.net/fidodido/archive/2005/08/04/9181.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/fidodido/comments/commentRss/9181.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/fidodido/services/trackbacks/9181.html</trackback:ping><description><![CDATA[<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0" align=center><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0">“策略模式”的出现，是为了提供一套相互之间可灵活替换的算法，在不影响上层接口的情况下，用户可以自由选择不同的算法完成逻辑。</SPAN></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">策略模式的</SPAN><SPAN lang=EN-US><FONT face=Verdana>UML</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">示意图如下：</SPAN><SPAN lang=EN-US><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p><FONT face=Verdana> </P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0" align=center></FONT></o:p></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><IMG height=228 alt=r_image002.jpg src="http://www.blogjava.net/images/blogjava_net/fidodido/2507/r_image002.jpg" width=521 border=0></SPAN> </P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: center; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0" align=center><SPAN lang=EN-US><?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><v:shapetype id=_x0000_t75 coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></v:path><o:lock v:ext="edit" aspectratio="t"></o:lock></v:shapetype></SPAN></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><SPAN lang=EN-US><o:p><FONT face=Verdana> </FONT></o:p></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">其中算法的模型接口在“抽象策略”中定义，各具象策略实现不同的策略。“消费</SPAN><SPAN lang=EN-US><FONT face=Verdana>API</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">”就是调用不同算法的类，在其内部根据不同需要选择不同的算法。有时需要将具象策略实例化后再传给其它类，这时可以使用<I style="mso-bidi-font-style: normal">“简单工厂”（</I></SPAN><I style="mso-bidi-font-style: normal"><SPAN lang=EN-US><FONT face=Verdana>Simple Factory</FONT></SPAN></I><I style="mso-bidi-font-style: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">）</SPAN></I><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">或<I style="mso-bidi-font-style: normal">“工厂方法”（</I></SPAN><I style="mso-bidi-font-style: normal"><SPAN lang=EN-US><FONT face=Verdana>Factory Method</FONT></SPAN></I><I style="mso-bidi-font-style: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">）</SPAN></I><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">生成所需的具象策略。下面就以我正在做的一个项目，简化一下后说明一下策略模式的使用。</SPAN></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">该项目是一个小型的商业网站，逻辑层由</SPAN><SPAN lang=EN-US><FONT face=Verdana>Servlet</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">实现。用户有一个需求，需要从数据库调出商品信息后能够对记录按名称（</SPAN><SPAN lang=EN-US><FONT face=Verdana>name</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">）、规格（</SPAN><SPAN lang=EN-US><FONT face=Verdana>standard</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">）、价格（</SPAN><SPAN lang=EN-US><FONT face=Verdana>price</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">）和注册日期（</SPAN><SPAN lang=EN-US><FONT face=Verdana>register date</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">）进行排序。虽然可以考虑按不同的排序关键字使用不同的</SPAN><SPAN lang=EN-US><FONT face=Verdana>sql</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">语句（即不同的</SPAN><SPAN lang=EN-US><FONT face=Verdana>order by</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">）查询数据库。但这样做的网络数据流量太大，每次需要从数据库完整地取回一个数据集（</SPAN><SPAN lang=EN-US><FONT face=Verdana>ResultSet</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">），所以我选择了将数据集一次取到客户端的一个</SPAN><SPAN lang=EN-US><FONT face=Verdana>List</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">中，然后在客户端按不同的关键字对</SPAN><SPAN lang=EN-US><FONT face=Verdana>List</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">进行排序。</SPAN></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><SPAN lang=EN-US><FONT face=Verdana>java.util.Collections</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">类中有一个</SPAN><I style="mso-bidi-font-style: normal"><SPAN lang=EN-US><FONT face=Verdana>public static void sort(List list, Comparator comparator)</FONT></SPAN></I><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">的方法，可以按照不同的</SPAN><SPAN lang=EN-US><FONT face=Verdana>Comparator</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">对象对</SPAN><SPAN lang=EN-US><FONT face=Verdana>list</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">进行排序，它使用的是快速排序，所以效率非常高。而</SPAN><SPAN lang=EN-US><FONT face=Verdana>java.util.Comparator</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">是一个接口：</SPAN></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><SPAN lang=EN-US><o:p><FONT face=Verdana> </FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt; mso-char-indent-count: 2.0"><I style="mso-bidi-font-style: normal"><SPAN lang=EN-US style="FONT-SIZE: 9pt"><FONT face=Verdana></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">package java.util;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG id=Codehighlighter1_57_139_Open_Image onclick="this.style.display='none'; Codehighlighter1_57_139_Open_Text.style.display='none'; Codehighlighter1_57_139_Closed_Image.style.display='inline'; Codehighlighter1_57_139_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_57_139_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_57_139_Closed_Text.style.display='none'; Codehighlighter1_57_139_Open_Image.style.display='inline'; Codehighlighter1_57_139_Open_Text.style.display='inline';" src="http://www.blogjava.net/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">interface</SPAN><SPAN style="COLOR: #000000"> Comparator </SPAN><SPAN id=Codehighlighter1_57_139_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.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_57_139_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>  boolean equals(Object </SPAN><SPAN style="COLOR: #0000ff">object</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> compare(Object </SPAN><SPAN style="COLOR: #0000ff">object</SPAN><SPAN style="COLOR: #000000">, Object object1);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt; mso-char-indent-count: 2.0"></FONT></SPAN></I><SPAN lang=EN-US><o:p><FONT face=Verdana> </FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">其中和排序有关的是</SPAN><SPAN lang=EN-US><FONT face=Verdana>compare</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">方法，它返回一个整数，若第一个参数比第二个参数“大”，则返回一个正数，若“小”则返回一个负数，若“相等”则返回</SPAN><SPAN lang=EN-US><FONT face=Verdana>0</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">，这里的“大”、“小”、“相等”是由</SPAN><SPAN lang=EN-US><FONT face=Verdana>compare</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">方法具体实现定义的一种比较标准。由这个方法不禁想到</SPAN><SPAN lang=EN-US><FONT face=Verdana>C</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">语言中</SPAN><SPAN lang=EN-US><FONT face=Verdana>qsort</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">函数中使用的函数指针</SPAN><I style="mso-bidi-font-style: normal"><SPAN lang=EN-US><FONT face=Verdana>int *compare(*,*)</FONT></SPAN></I><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">，</SPAN><SPAN lang=EN-US><FONT face=Verdana>JAVA</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">中之所以没有函数指针，就是用接口取代了（更详细的介绍见《</SPAN><SPAN lang=EN-US><FONT face=Verdana>Effective Java</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">》中第</SPAN><SPAN lang=EN-US><FONT face=Verdana>22</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">条“用类和接口来代替函数指针”）。</SPAN></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">很明显，</SPAN><SPAN lang=EN-US><FONT face=Verdana>Comparator</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">接口就是我们的“抽象策略”，</SPAN><SPAN lang=EN-US><FONT face=Verdana>sort</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">方法就是我们的“消费</SPAN><SPAN lang=EN-US><FONT face=Verdana>API</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">”，而不同的“具象策略”就是我们从</SPAN><SPAN lang=EN-US><FONT face=Verdana>Comparator</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">接口实现的根据不同关键字排序的类。</SPAN></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">整个排序模型的</SPAN><SPAN lang=EN-US><FONT face=Verdana>UML</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">图如下，其中为了作图方便，我从</SPAN><SPAN lang=EN-US><FONT face=Verdana>Comparator</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">继承了一个接口</SPAN><SPAN lang=EN-US><FONT face=Verdana>ItemComparator</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">，根据不同的关键字从</SPAN><SPAN lang=EN-US><FONT face=Verdana>ItemComparator</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">接口泛化了</SPAN><SPAN lang=EN-US><FONT face=Verdana>NameComparator</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">类，</SPAN><SPAN lang=EN-US><FONT face=Verdana>PriceComparator</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">类，</SPAN><SPAN lang=EN-US><FONT face=Verdana>RegisterDateComparator</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">类和</SPAN><SPAN lang=EN-US><FONT face=Verdana>StandardComparator</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">类。实际运用中不需要这个接口，四个类可以直接从</SPAN><SPAN lang=EN-US><FONT face=Verdana>Comparator</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">泛化。</SPAN><SPAN lang=EN-US><FONT face=Verdana>ItemBean</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">是一个封装了商品信息的</SPAN><SPAN lang=EN-US><FONT face=Verdana>bean</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">，</SPAN><SPAN lang=EN-US><FONT face=Verdana>List</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">中存放的就是这些</SPAN><SPAN lang=EN-US><FONT face=Verdana>bean</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">。</SPAN><SPAN lang=EN-US><FONT face=Verdana>ItemSort</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">和</SPAN><SPAN lang=EN-US><FONT face=Verdana>ItemComparator</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">以及四个具体类实现了“简单工厂”模式，并封装了</SPAN><SPAN lang=EN-US><FONT face=Verdana>sort</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">方法。</SPAN></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0" align=center><SPAN lang=EN-US><o:p><FONT face=Verdana> <IMG height=663 alt=o_strategy.dfPackage.jpg src="http://www.blogjava.net/images/blogjava_net/fidodido/2507/o_strategy.dfPackage.jpg" width=590 border=0></FONT></o:p></SPAN><SPAN lang=EN-US><o:p><FONT face=Verdana> <BR></P></FONT></o:p></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><BR>    下面是具体的代码（</SPAN><SPAN lang=EN-US><FONT face=Verdana>StandardComparator</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">类的代码与</SPAN><SPAN lang=EN-US><FONT face=Verdana>NameComparator</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">类的代码大同小异，在这里不列出）：</SPAN></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><SPAN lang=EN-US><o:p><FONT face=Verdana> </FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21.1pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US><FONT face=Verdana>NameComparator</FONT></SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">类：</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><SPAN lang=EN-US><o:p><FONT face=Verdana> </FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt; mso-char-indent-count: 2.0"><I style="mso-bidi-font-style: normal"><SPAN lang=EN-US style="FONT-SIZE: 9pt"><FONT face=Verdana></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">package com.lim.designpatterns.strategy;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG id=Codehighlighter1_95_352_Open_Image onclick="this.style.display='none'; Codehighlighter1_95_352_Open_Text.style.display='none'; Codehighlighter1_95_352_Closed_Image.style.display='inline'; Codehighlighter1_95_352_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_95_352_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_95_352_Closed_Text.style.display='none'; Codehighlighter1_95_352_Open_Image.style.display='inline'; Codehighlighter1_95_352_Open_Text.style.display='inline';" src="http://www.blogjava.net/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"> NameComparator implements ItemComparator</SPAN><SPAN id=Codehighlighter1_95_352_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.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_95_352_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG id=Codehighlighter1_115_116_Open_Image onclick="this.style.display='none'; Codehighlighter1_115_116_Open_Text.style.display='none'; Codehighlighter1_115_116_Closed_Image.style.display='inline'; Codehighlighter1_115_116_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_115_116_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_115_116_Closed_Text.style.display='none'; Codehighlighter1_115_116_Open_Image.style.display='inline'; Codehighlighter1_115_116_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>  NameComparator()</SPAN><SPAN id=Codehighlighter1_115_116_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.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_115_116_Open_Text><SPAN style="COLOR: #000000">{}</SPAN></SPAN><SPAN style="COLOR: #000000">  </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> 将构造器封装，包外的类欲得到Comparator实例只能通过简单工厂</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_199_350_Open_Image onclick="this.style.display='none'; Codehighlighter1_199_350_Open_Text.style.display='none'; Codehighlighter1_199_350_Closed_Image.style.display='inline'; Codehighlighter1_199_350_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_199_350_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_199_350_Closed_Text.style.display='none'; Codehighlighter1_199_350_Open_Image.style.display='inline'; Codehighlighter1_199_350_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> compare(Object o1,Object o2)</SPAN><SPAN id=Codehighlighter1_199_350_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.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_199_350_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>    String name1</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">((ItemBean)o1).getName();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>    String name2</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">((ItemBean)o2).getName();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000"> name1.compareTo(name2);  </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> 调用String的CompareTo方法</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top></SPAN><SPAN style="COLOR: #000000">  }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt; mso-char-indent-count: 2.0"></FONT></SPAN></I></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><SPAN lang=EN-US><o:p><FONT face=Verdana> </FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21.1pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US><FONT face=Verdana>PriceComparator</FONT></SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">类</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><SPAN lang=EN-US><o:p><FONT face=Verdana> </FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt; mso-char-indent-count: 2.0"><I style="mso-bidi-font-style: normal"><SPAN lang=EN-US style="FONT-SIZE: 9pt"><FONT face=Verdana></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">package com.lim.designpatterns.strategy;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG id=Codehighlighter1_96_345_Open_Image onclick="this.style.display='none'; Codehighlighter1_96_345_Open_Text.style.display='none'; Codehighlighter1_96_345_Closed_Image.style.display='inline'; Codehighlighter1_96_345_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_96_345_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_96_345_Closed_Text.style.display='none'; Codehighlighter1_96_345_Open_Image.style.display='inline'; Codehighlighter1_96_345_Open_Text.style.display='inline';" src="http://www.blogjava.net/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"> PriceComparator implements ItemComparator</SPAN><SPAN id=Codehighlighter1_96_345_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.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_96_345_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG id=Codehighlighter1_117_118_Open_Image onclick="this.style.display='none'; Codehighlighter1_117_118_Open_Text.style.display='none'; Codehighlighter1_117_118_Closed_Image.style.display='inline'; Codehighlighter1_117_118_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_117_118_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_117_118_Closed_Text.style.display='none'; Codehighlighter1_117_118_Open_Image.style.display='inline'; Codehighlighter1_117_118_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>  PriceComparator()</SPAN><SPAN id=Codehighlighter1_117_118_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.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_117_118_Open_Text><SPAN style="COLOR: #000000">{}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_162_343_Open_Image onclick="this.style.display='none'; Codehighlighter1_162_343_Open_Text.style.display='none'; Codehighlighter1_162_343_Closed_Image.style.display='inline'; Codehighlighter1_162_343_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_162_343_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_162_343_Closed_Text.style.display='none'; Codehighlighter1_162_343_Open_Image.style.display='inline'; Codehighlighter1_162_343_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> compare(Object o1,Object o2)</SPAN><SPAN id=Codehighlighter1_162_343_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.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_162_343_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>    Double price1</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Double(((ItemBean)o1).getPrice());<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>    Double price2</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Double(((ItemBean)o2).getPrice());<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000"> price1.compareTo(price2);  </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> 调用Double的CompareTo方法</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top></SPAN><SPAN style="COLOR: #000000">  }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV></DIV>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt; mso-char-indent-count: 2.0"></FONT></SPAN></I><SPAN lang=EN-US><o:p><FONT face=Verdana> </FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21.1pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US><FONT face=Verdana>RegisterDateComparator</FONT></SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">类</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><SPAN lang=EN-US><o:p><FONT face=Verdana> </FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt; mso-char-indent-count: 2.0"><I style="mso-bidi-font-style: normal"><SPAN lang=EN-US style="FONT-SIZE: 9pt"><FONT face=Verdana></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">package com.lim.designpatterns.strategy;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>import java.util.</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG id=Codehighlighter1_124_360_Open_Image onclick="this.style.display='none'; Codehighlighter1_124_360_Open_Text.style.display='none'; Codehighlighter1_124_360_Closed_Image.style.display='inline'; Codehighlighter1_124_360_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_124_360_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_124_360_Closed_Text.style.display='none'; Codehighlighter1_124_360_Open_Image.style.display='inline'; Codehighlighter1_124_360_Open_Text.style.display='inline';" src="http://www.blogjava.net/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"> RegisterDateComparator implements ItemComparator</SPAN><SPAN id=Codehighlighter1_124_360_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.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_124_360_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG id=Codehighlighter1_152_153_Open_Image onclick="this.style.display='none'; Codehighlighter1_152_153_Open_Text.style.display='none'; Codehighlighter1_152_153_Closed_Image.style.display='inline'; Codehighlighter1_152_153_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_152_153_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_152_153_Closed_Text.style.display='none'; Codehighlighter1_152_153_Open_Image.style.display='inline'; Codehighlighter1_152_153_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>  RegisterDateComparator()</SPAN><SPAN id=Codehighlighter1_152_153_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.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_152_153_Open_Text><SPAN style="COLOR: #000000">{}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG id=Codehighlighter1_197_358_Open_Image onclick="this.style.display='none'; Codehighlighter1_197_358_Open_Text.style.display='none'; Codehighlighter1_197_358_Closed_Image.style.display='inline'; Codehighlighter1_197_358_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_197_358_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_197_358_Closed_Text.style.display='none'; Codehighlighter1_197_358_Open_Image.style.display='inline'; Codehighlighter1_197_358_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>  </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> compare(Object o1,Object o2)</SPAN><SPAN id=Codehighlighter1_197_358_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.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_197_358_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>    Date date1</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">((ItemBean)o1).getRegisterDate();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>    Date date2</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">((ItemBean)o2).getRegisterDate();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000"> date1.compareTo(date2);  </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> 调用Date的CompareTo方法</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top></SPAN><SPAN style="COLOR: #000000">  }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV></DIV>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt; mso-char-indent-count: 2.0"></FONT></SPAN></I><SPAN lang=EN-US><o:p><FONT face=Verdana> </FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21.1pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US><FONT face=Verdana>ItemSort</FONT></SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">类</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><SPAN lang=EN-US><o:p><FONT face=Verdana> </FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt; mso-char-indent-count: 2.0"><I style="mso-bidi-font-style: normal"><SPAN lang=EN-US style="FONT-SIZE: 9pt"><FONT face=Verdana></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">package com.lim.designpatterns.strategy;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>import java.util.</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG id=Codehighlighter1_84_486_Open_Image onclick="this.style.display='none'; Codehighlighter1_84_486_Open_Text.style.display='none'; Codehighlighter1_84_486_Closed_Image.style.display='inline'; Codehighlighter1_84_486_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_84_486_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_84_486_Closed_Text.style.display='none'; Codehighlighter1_84_486_Open_Image.style.display='inline'; Codehighlighter1_84_486_Open_Text.style.display='inline';" src="http://www.blogjava.net/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"> ItemSort</SPAN><SPAN id=Codehighlighter1_84_486_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.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_84_486_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG id=Codehighlighter1_140_193_Open_Image onclick="this.style.display='none'; Codehighlighter1_140_193_Open_Text.style.display='none'; Codehighlighter1_140_193_Closed_Image.style.display='inline'; Codehighlighter1_140_193_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_140_193_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_140_193_Closed_Text.style.display='none'; Codehighlighter1_140_193_Open_Image.style.display='inline'; Codehighlighter1_140_193_Open_Text.style.display='inline';" src="http://www.blogjava.net/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"> List sort(List items,ItemComparator c)</SPAN><SPAN id=Codehighlighter1_140_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.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_140_193_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>    Collections.sort(items,c);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000"> items;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>  }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.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"> final ItemComparator NAME</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> NameComparator();  </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> 简单工厂</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.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"> final ItemComparator PRICE</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> PriceComparator();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.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"> final ItemComparator STANDARD</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> StandardComparator();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.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"> final ItemComparator REG_DATE</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> RegisterDateComparator();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV></DIV>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt; mso-char-indent-count: 2.0"></FONT></SPAN></I><SPAN lang=EN-US><o:p><FONT face=Verdana> </FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21.1pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US><FONT face=Verdana>TestItemSort</FONT></SPAN></B><B style="mso-bidi-font-weight: normal"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">类</SPAN><SPAN lang=EN-US><o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 7.8pt 0cm 0pt; TEXT-INDENT: 21pt; mso-para-margin-top: .5gd; mso-char-indent-count: 2.0"><SPAN lang=EN-US><o:p><FONT face=Verdana> </FONT></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 18pt; mso-char-indent-count: 2.0"><I style="mso-bidi-font-style: normal"><SPAN lang=EN-US style="FONT-SIZE: 9pt"><FONT face=Verdana></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">package com.lim.designpatterns.strategy;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>import java.util.</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG id=Codehighlighter1_88_424_Open_Image onclick="this.style.display='none'; Codehighlighter1_88_424_Open_Text.style.display='none'; Codehighlighter1_88_424_Closed_Image.style.display='inline'; Codehighlighter1_88_424_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_88_424_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_88_424_Closed_Text.style.display='none'; Codehighlighter1_88_424_Open_Image.style.display='inline'; Codehighlighter1_88_424_Open_Text.style.display='inline';" src="http://www.blogjava.net/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"> TestItemSort</SPAN><SPAN id=Codehighlighter1_88_424_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.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_88_424_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG id=Codehighlighter1_130_422_Open_Image onclick="this.style.display='none'; Codehighlighter1_130_422_Open_Text.style.display='none'; Codehighlighter1_130_422_Closed_Image.style.display='inline'; Codehighlighter1_130_422_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_130_422_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_130_422_Closed_Text.style.display='none'; Codehighlighter1_130_422_Open_Image.style.display='inline'; Codehighlighter1_130_422_Open_Text.style.display='inline';" src="http://www.blogjava.net/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_130_422_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.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_130_422_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>    List items</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> ArrayList();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>    </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> 向List添加条目</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>    items</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">ItemSort.sort(items,ItemSort.NAME);  </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> 按名称排序</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>    items</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">ItemSort.sort(items,ItemSort.PRICE);  </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> 按价格排序</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>    items</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">ItemSort.sort(items,ItemSort.REG_DATE);  </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> 按注册日期排序</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>    items</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">ItemSort.sort(items,ItemSort.STANDARD);  </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000"> 按规格排序</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top></SPAN><SPAN style="COLOR: #000000">  }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV></DIV></FONT></SPAN></I><img src ="http://www.blogjava.net/fidodido/aggbug/9181.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/fidodido/" target="_blank">^ Mustang ^</a> 2005-08-04 12:37 <a href="http://www.blogjava.net/fidodido/archive/2005/08/04/9181.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>