﻿<?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-自然-文章分类-Architecture</title><link>http://www.blogjava.net/masen/category/45120.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 09 Jan 2015 10:54:13 GMT</lastBuildDate><pubDate>Fri, 09 Jan 2015 10:54:13 GMT</pubDate><ttl>60</ttl><item><title>UML中关系图解(转)</title><link>http://www.blogjava.net/masen/articles/422141.html</link><dc:creator>Masen</dc:creator><author>Masen</author><pubDate>Thu, 08 Jan 2015 13:52:00 GMT</pubDate><guid>http://www.blogjava.net/masen/articles/422141.html</guid><wfw:comment>http://www.blogjava.net/masen/comments/422141.html</wfw:comment><comments>http://www.blogjava.net/masen/articles/422141.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/masen/comments/commentRss/422141.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/masen/services/trackbacks/422141.html</trackback:ping><description><![CDATA[<h2>关系列表：</h2><ol style="font-family: Arial; line-height: 26px; background-color: #ffffff;"><li>继承关系(Generalization)；</li><li>实现关系(Realization)；</li><li>依赖关系(Dependency)；</li><li>关联关系(Association)；</li><li>有方向的关联(DirectedAssociation)；</li><li>聚合关系(Aggregation)；</li><li>组合关系(Composition)；</li></ol><h2><a name="t1" style="color: rgb(255, 153, 0);"></a>继承关系（Generalization）：</h2><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: center; background-color: #ffffff;"><a href="http://my.oschina.net/uploads/space/2010/1116/214702_sAEm_98204.jpg" target="_blank" style="color: #ff9900; text-decoration: none;"><img src="http://my.oschina.net/uploads/space/2010/1116/214702_sAEm_98204.jpg" alt="" style="border: none; max-width: 100%; cursor: pointer;" /></a></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: center; background-color: #ffffff;">Class B继承与Class A</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">继承指的是一个类（称为子类、子接口）继承另外的一个类（称为父类、父接口）的功能，并可以增加它自己的新功能的能力，继承是类与类或者接口与接口 之间最常见的关系之一；在Java中此类关系通过关键字extends明确标识，在设计时一般没有争议性；</p><h2><a name="t2" style="color: rgb(255, 153, 0);"></a>实现关系（Realization）：</h2><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: center; background-color: #ffffff;"><a href="http://hi.csdn.net/attachment/201005/9/0_1273449367ILQy.gif" target="_blank" style="color: #ff9900; text-decoration: none;"><img src="http://hi.csdn.net/attachment/201005/9/0_1273449367ILQy.gif" alt="" style="border: none; max-width: 100%; cursor: pointer;" /></a></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: center; background-color: #ffffff;">Class A实现了Interface A</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">实现指的是一个class类实现interface接口（可以是多个）的功能；实现是类与接 口之间最常见的关系之一；在Java中此类关系通过关键字implements明确标识，在设计时一般没有争议性；</p><h2><a name="t3" style="color: rgb(255, 153, 0);"></a>依赖关系（Dependency）：</h2><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: center; background-color: #ffffff;"><a href="http://my.oschina.net/uploads/space/2010/1116/215239_GY4o_98204.jpg" target="_blank" style="color: #ff9900; text-decoration: none;"><img src="http://my.oschina.net/uploads/space/2010/1116/215239_GY4o_98204.jpg" alt="" style="border: none; max-width: 100%; cursor: pointer;" /></a></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: center; background-color: #ffffff;">ClassA依赖于ClassB</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">可以简单的理解，就是一个类A使用到了另一个类B，而这种使用关系是具有偶然性的、临时性 的、非常弱的，但是B类的变化会影响到A；表现在代码层面，为类B作为参数被类A在某个method方法中使用；</p><h2><a name="t4" style="color: rgb(255, 153, 0);"></a>关联关系（Association）：</h2><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: center; background-color: #ffffff;"><a href="http://my.oschina.net/uploads/space/2010/1116/215250_no6f_98204.jpg" target="_blank" style="color: #ff9900; text-decoration: none;"><img src="http://my.oschina.net/uploads/space/2010/1116/215250_no6f_98204.jpg" alt="" style="border: none; max-width: 100%; cursor: pointer;" /></a></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: center; background-color: #ffffff;">ClassA与ClassB相互关联</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">这里的关联关系分的比较细，把相互关联和有方向的关联区分开了，相互他体现的是两个类、或者 类与接口之间语义级别的一种强依赖关系，是一种长期的稳定的关系；表现在代码层面，为被关联类以类属性的形式出现在关联类中，也可能是关联类引用了一个类 型为被关联类的全局变量；</p><h2><a name="t5" style="color: rgb(255, 153, 0);"></a>有方向的关联（DirectedAssociation）：</h2><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: center; background-color: #ffffff;"><a href="http://my.oschina.net/uploads/space/2010/1116/215305_dpXG_98204.jpg" target="_blank" style="color: #ff9900; text-decoration: none;"><img src="http://my.oschina.net/uploads/space/2010/1116/215305_dpXG_98204.jpg" alt="" style="border: none; max-width: 100%; cursor: pointer;" /></a></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: center; background-color: #ffffff;">ClassA关联于ClassB</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">是关联的一种特别形式，是单向的；表现在代码层面，为被关联类B以类属性的形式出现在关联类 A中，也可能是关联类A引用了一个类型为被关联类B的全局变量；</p><h2><a name="t6" style="color: rgb(255, 153, 0);"></a>聚合关系（Aggregation）：</h2><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: center; background-color: #ffffff;"><a href="http://my.oschina.net/uploads/space/2010/1116/215316_n254_98204.jpg" target="_blank" style="color: #220000; text-decoration: none;"><img src="http://my.oschina.net/uploads/space/2010/1116/215316_n254_98204.jpg" alt="" style="border: none; max-width: 100%; cursor: pointer;" /></a></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: center; background-color: #ffffff;">计算机 has-a cpu</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">聚合是关联关系的一种特例，他体现的是整体与部分、拥有的关系，即has-a的关系，此时整 体与部分之间是可分离的，他们可以具有各自的生命周期，部分可以属于多个整体对象，也可以为多个整体对象共享；比如计算机与CPU；表现在代码层面，和关 联关系是一致的，只能从语义级别来区分；</p><h2><a name="t7" style="color: rgb(255, 153, 0);"></a>组合关系（Composition）：</h2><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: center; background-color: #ffffff;"><a href="http://my.oschina.net/uploads/space/2010/1116/215327_tFiB_98204.jpg" target="_blank" style="color: #ff9900; text-decoration: none;"><img src="http://my.oschina.net/uploads/space/2010/1116/215327_tFiB_98204.jpg" alt="" style="border: none; max-width: 100%; cursor: pointer;" /></a></p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: center; background-color: #ffffff;">孕妇 contains-a 胎儿</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; text-align: center; background-color: #ffffff;">&nbsp;</p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">组合也是关联关系的一种特例，他体现的是一种contains-a的关系，这种关系比聚合更 强，也称为强聚合；他同样体现整体与部分间的关系，但此时整体与部分是不可分的，整体的生命周期结束也就意味着部分的生命周期结束；孕妇死了胎儿自然也就 死了；表现在代码层面，和关联关系是一致的，只能从语义级别来区分</p><img src ="http://www.blogjava.net/masen/aggbug/422141.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/masen/" target="_blank">Masen</a> 2015-01-08 21:52 <a href="http://www.blogjava.net/masen/articles/422141.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>远程调用方案的比较（转）</title><link>http://www.blogjava.net/masen/articles/323234.html</link><dc:creator>Masen</dc:creator><author>Masen</author><pubDate>Thu, 10 Jun 2010 06:57:00 GMT</pubDate><guid>http://www.blogjava.net/masen/articles/323234.html</guid><wfw:comment>http://www.blogjava.net/masen/comments/323234.html</wfw:comment><comments>http://www.blogjava.net/masen/articles/323234.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/masen/comments/commentRss/323234.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/masen/services/trackbacks/323234.html</trackback:ping><description><![CDATA[<div>几种通讯协议的比较</div>
<div>一、综述</div>
<div>本文比较了RMI，Hessian，Burlap，Httpinvoker，web service等5种通讯协议的在不同的数据结构和不同数据量时的传输性能。</div>
<div>RMI是java语言本身提供的远程通讯协议，稳定高效，是EJB的基础。但它只能用于JAVA程序之间的通讯。</div>
<div>Hessian和Burlap是caucho公司提供的开源协议，基于HTTP传输，服务端不用开防火墙端口。协议的规范公开，可以用于任意语 言。</div>
<div>Httpinvoker是SpringFramework提供的远程通讯协议，只能用于JAVA程序间的通讯，且服务端和客户端必须使用 SpringFramework。</div>
<div>Web service是连接异构系统或异构语言的首选协议，它使用SOAP形式通讯，可以用于任何语言，目前的许多开发工具对其的支持也很好。</div>
<div><br />
</div>
<div>测试结果显示，几种协议的通讯效率依次为：</div>
<div>RMI &gt; Httpinvoker &gt;= Hessian &gt;&gt; Burlap &gt;&gt; web service</div>
<div>RMI不愧是JAVA的首选远程调用协议，非常高效稳定，特别是在大数据量的情况下，与其他通讯协议的差距尤为明显。</div>
<div>HttpInvoker使用java的序列化技术传输对象，与RMI在本质上是一致的。从效率上看，两者也相差无几，HttpInvoker与 RMI的传输时间基本持平。</div>
<div>Hessian在传输少量对象时，比RMI还要快速高效，但传输数据结构复杂的对象或大量数据对象时，较RMI要慢20%左右。</div>
<div>Burlap仅在传输1条数据时速度尚可，通常情况下，它的毫时是RMI的3倍。</div>
<div>Web Service的效率低下是众所周知的，平均来看，Web Service的通讯毫时是RMI的10倍。</div>
<div><br />
</div>
<div><br />
</div>
<div><br />
</div>
<div><br />
</div>
<div>二、结果分析</div>
<div>1、直接调用</div>
<div>直接调用的所有毫时都接近0，这说明程序处理几乎没有花费时间，记录的全部时间都是远程调用耗费的。</div>
<div>2、RMI调用</div>
<div>与设想的一样，RMI理所当然是最快的，在几乎所有的情况下，它的毫时都是最少的。特别是在数据结构复杂，数据量大的情况下，与其他协议的差距尤 为明显。</div>
<div>为了充分发挥RMI的性能，另外做了测试类，不使用Spring，用原始的RMI形式（继承UnicastRemoteObject对象）提供服 务并远程调用，与Spring对POJO包装成的RMI进行效率比较。结果显示：两者基本持平，Spring提供的服务还稍快些。</div>
<div>初步认为，这是因为Spring的代理和缓存机制比较强大，节省了对象重新获取的时间。</div>
<div>3、Hessian调用</div>
<div>caucho公司的resin服务器号称是最快的服务器，在java领域有一定的知名度。Hessian做为resin的组成部分，其设计也非常 精简高效，实际运行情况也证明了这一点。平均来看，Hessian较RMI要慢20%左右，但这只是在数据量特别大，数据结构很复杂的情况下才能体现出 来，中等或少量数据时，Hessian并不比RMI慢。</div>
<div>Hessian的好处是精简高效，可以跨语言使用，而且协议规范公开，我们可以针对任意语言开发对其协议的实现。目前已有实现的语言 有：java, c++, .net, python, ruby。还没有delphi的实现。</div>
<div>另外，Hessian与WEB服务器结合非常好，借助WEB服务器的成熟功能，在处理大量用户并发访问时会有很大优势，在资源分配，线程排队，异 常处理等方面都可以由成熟的WEB服务器保证。而RMI本身并不提供多线程的服务器。而且，RMI需要开防火墙端口，Hessian不用。</div>
<div>4、Burlap调用</div>
<div>Burlap与Hessian都是caucho公司的开源产品，只不过Hessian采用二进制的方式，而Burlap采用xml的格式。</div>
<div>测试结果显示，Burlap在数据结构不复杂，数据量中等的情况下，效率还是可以接受的，但如果数据量大，效率会急剧下降。平均计 算，Burlap的调用毫时是RMI的3倍。</div>
<div>我认为，其效率低有两方面的原因，一个是XML数据描述内容太多，同样的数据结构，其传输量要大很多；另一方面，众所周知，对xml的解析是比较 费资源的，特别对于大数据量情况下更是如此。</div>
<div>5、HttpInvoker调用</div>
<div>HttpInvoker是SpringFramework提供的JAVA远程调用方法，使用java的序列化机制处理对象的传输。从测试结果看， 其效率还是可以的，与RMI基本持平。</div>
<div>不过，它只能用于JAVA语言之间的通讯，而且，要求客户端和服务端都使用SPRING框架。</div>
<div>另外，HttpInvoker 并没有经过实践的检验，目前还没有找到应用该协议的项目。</div>
<div>6、web service调用</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; 本次测试选用了apache的AXIS组件作为WEB SERVICE的实现，AXIS在WEB SERVICE领域相对成熟老牌。</div>
<div>为了仅测试数据传输和编码、解码的时间，客户端和服务端都使用了缓存，对象只需实例化一次。但是，测试结果显示，web service的效率还是要比其他通讯协议慢10倍。</div>
<div>如果考虑到多个引用指向同一对象的传输情况，web service要落后更多。因为RMI，Hessian等协议都可以传递引用，而web service有多少个引用，就要复制多少份对象实体。</div>
<div>Web service传输的冗余信息过多是其速度慢的原因之一，监控发现，同样的访问请求，描述相同的数据，web service返回的数据量是hessian协议的6.5倍。另外，WEB SERVICE的处理也很毫时，目前的xml解析器效率普遍不高，处理xml &lt;-&gt; bean很毫资源。从测试结果看，异地调用比本地调用要快，也从侧面说明了其毫时主要用在编码和解码xml文件上。这比冗余信息更为严重，冗余信息占用的 只是网络带宽，而每次调用的资源耗费直接影响到服务器的负载能力。（MS的工程师曾说过，用WEB SERVICE不能负载100个以上的并发用户。）</div>
<div>测试过程中还发现，web service编码不甚方便，对非基本类型需要逐个注册序列化和反序列化类，很麻烦，生成stub更累，不如spring + RMI/hessian处理那么流畅简洁。而且，web service不支持集合类型，只能用数组，不方便。&lt;/b&gt;</div>
<img src ="http://www.blogjava.net/masen/aggbug/323234.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/masen/" target="_blank">Masen</a> 2010-06-10 14:57 <a href="http://www.blogjava.net/masen/articles/323234.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java企业级应用架构设计中的分布式结构（转）</title><link>http://www.blogjava.net/masen/articles/321913.html</link><dc:creator>Masen</dc:creator><author>Masen</author><pubDate>Wed, 26 May 2010 07:17:00 GMT</pubDate><guid>http://www.blogjava.net/masen/articles/321913.html</guid><wfw:comment>http://www.blogjava.net/masen/comments/321913.html</wfw:comment><comments>http://www.blogjava.net/masen/articles/321913.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/masen/comments/commentRss/321913.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/masen/services/trackbacks/321913.html</trackback:ping><description><![CDATA[<span style="font-size: 12px; line-height: 26px; ">
<ul class="con" style="padding-top: 10px; padding-right: 24px; padding-bottom: 0px; padding-left: 24px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; line-height: 26px; font-size: 14px; ">
    <p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 28px; "><span style="font-size: 12px; ">
    </span></p>
    <div class="sum" style="padding-top: 0px; padding-right: 24px; padding-bottom: 0px; padding-left: 24px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">
    <ul class="summary" style="padding-top: 8px; padding-right: 16px; padding-bottom: 4px; padding-left: 16px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-style: initial; border-color: initial; line-height: 24px; width: 554px; font-size: 14px; color: #005197; background-color: #fefde8; border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; border-left-style: dashed; border-top-color: #dde6f1; border-right-color: #dde6f1; border-bottom-color: #dde6f1; border-left-color: #dde6f1; ">Java企业级应用架构设计是每个Java开发者不必学的知识，本文将对Java EE应用的架构与设计进行一些基础性的介绍，而这些内容构筑了整个Java EE应用开发的基础。</ul>
        </div>
        <ul class="con" style="padding-top: 10px; padding-right: 24px; padding-bottom: 0px; padding-left: 24px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; line-height: 26px; font-size: 14px; ">
            <p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 28px; "></p>
            <p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 28px; ">Java企业级应用架构设计中的分布式结构大致可以分为单级结构、2级结构、3级结构和N级结构。充分理解和应用分布式结构可以更好的理解当代网络计算的现状，设计出更优的企业级应用程序。</p>
            <p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 28px; ">长久以来，Java企业级版本（Java EE）已经成为了众多产业领域（如银行业、保险业、零售业、酒店业、旅游业以及电信业等等）进行企业商务应用开发和部署的平台选择。Java EE之所以应用如此广泛，其原因在于，Java EE可以为构建健壮、高扩展性的分布式应用系统提供标准化的平台，而这些应用所支持的范围可以涵盖从银行核心业务运作，到航空公司订票引擎之间的广大区域。不过，开发成功的Java EE应用也可能成为一项艰巨的任务，Java企业级应用架构设计在其中起着重要作用。</p>
            <p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 28px; ">首先Java EE平台自身所提供的丰富选择就足可以令人生畏。那些过剩的框架、实用程序类库、集成开发环境（IDE），以及可供选择的工具让一切都更加富有挑战性。因此，选择好合适的技术对于开发基于Java EE的软件来说至关重要。而那些拥有健壮架构与设计准则的技术，会对构建易于维护、重用以及扩展的应用系统大有裨益。<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            <br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            我们将首先回顾一下分布式计算的进化史以及n级结构。之后我将展示Java EE平台是如何解决分布式应用开发中的难点的。同时你还会了解模型-视图-控制器（MVC）结构准则。然后我会结合MVC准则与Java EE平台，来讲解多层Java EE应用结构。<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            <br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            在了解了应用系统架构之后，我将把注意力集中到基于面向对象原则的Java EE应用开发上。我同时还会讲解如何使用设计模式来简化设计过程，以及如何选择最佳的实践范例。此外我还会触及Sun公司的Java BluePrints所收录的设计模式目录，其内容在Deepak Alur et al的《核心J2EE设计模式》（Prentice Hall出版社，2003年）一书中有详细的介绍。在文章的最后，我将介绍通用建模语言（UML）以及其在可视化Java EE文档设计与架构之中所扮演的的角色。<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            <br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            <strong style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">分布式计算进化史</strong><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            <br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            在分布式计算中，一个应用会被划分为若干稍小的部件，并同时运行在不同的计算机上。这种计算方式又被称为&#8220;网络计算&#8221;，因为这些部件通常会通过建立在TCP/IP或者UDP协议之上的某些协议进行通讯。这些稍小的应用部件被称为&#8220;级&#8221;，每一级都可以向其他连接级独立提供一类服务。而&#8220;级&#8221;又可以被细化为若干&#8220;层&#8221;，以便降低功能的粒度。大多数Java企业级应用架构设计都应具有三个不同的层：</p>
            <p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 28px; ">◆表现层负责用户接口。</p>
            <p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 28px; ">◆业务层执行业务逻辑。在运行过程中，它还会与数据访问层进行交互。</p>
            <p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 28px; ">◆数据访问层负责对存储在企业信息系统（EIS）中的数据进行存取等操作。<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            <br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            通过分析分布式计算结构的跃迁史，我们可以更好的理解当代网络计算的现状。在接下来的几节中，我将用几个恰当的例子介绍分布式结构的变迁。<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            <br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            <strong style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">单级结构<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            </strong>&nbsp;<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            单级结构的使用可以追溯到那些使用简易终端连接巨型主机的日子。在这种结构中，用户接口、业务逻辑以及数据等所有应用构成层都被配置在同一个物理主机中。用户通过终端机或控制台与系统进行交互，而这种方式只具有非常有限的文本处理能力（参见图1）</p>
            <p align="center" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 28px; "><img class="fit-image" height="179" alt="Java企业级应用架构设计中的单层结构" src="http://images.51cto.com/files/uploadimg/20090825/1345190.jpg" width="330" border="0" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            <font size="2" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">图1. 单层结构（图中文字：Console——&#8220;控制台&#8221;；Dumb Terminal——&#8220;简易终端&#8221;；Mainframe——主机）</font></p>
            <p align="left" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 28px; "><strong style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">2级结构<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            </strong>&nbsp;<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            在1980年代早期，个人电脑（PC）变得非常流行，它比大型主机便宜，处理能力又比简易终端之类的设备强。PC的出现为真正的分布式（客户端——服务器，C/S)计算铺平了道路。作为客户端的PC现在可以独立运行客户接口（UI）程序，同时它还支持图形化客户接口（GUI），允许用户输入数据，并与服务器主机进行交互，而服务器主机现在只负责业务逻辑和数据的部分。当用户在客户端完成数据录入后，GUI程序可以选择性的进行数据有效性校验，之后将数据发送给服务器进行业务逻辑处理。Oracle基于表单的应用就是2级结构的优秀范例。表单的GUI存储在客户端PC中，而业务逻辑（包括代码以及存储过程）以及数据仍然保留在Oracle的数据库服务器中。<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            <br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            此后又出现了另外一种2级结构，在这种结构中，不只是用户接口（UI），连业务逻辑也被放到了客户端一级。这种应用的典型运行方式是直接连接数据库服务器进行各种数据库查询。这种客户端被称作&#8220;胖客户端&#8221;，因为这种结构将可执行代码的相当大一部分都放到了客户端一级（参见图2）。</p>
            <p align="center" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 28px; "><a href="http://images.51cto.com/files/uploadimg/20090825/1345191.jpg" target="_blank" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-decoration: underline; color: #0000ff; "><img class="fit-image" height="313" alt="Java企业级应用架构中的2级结构" src="http://images.51cto.com/files/uploadimg/20090825/1345191.jpg" width="406" border="0" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /></a><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            <font size="2" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">图2. 2级结构（Business Logic Layer——业务逻辑层；Optional——可选；User Interface Layer——用户接口层；Thick Client——胖客户端；Data Access Layer——数据访问层； Mainframe Server——服务器主机）</font></p>
            <p align="left" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 28px; "><strong style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">3级结构</strong><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            <br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            尽管2级&#8220;胖客户端&#8221;应用的开发很简单，但是任何用户接口或者业务逻辑的改变所导致的软件升级都需要在所有客户端上进行。幸运的是，在上世纪90年代中期，硬件成本已经变得越来越低，而CPU的运算能力却得到了巨大提升。与此同时，互联网的发展非常迅速，互联网应用的发展趋势已经逐渐显现，两者的结合最终导致了3级结构的产生。<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            <br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            在3级结构模型中，PC客户端只需要安装&#8220;瘦客户端&#8221;软件——比如浏览器——来显示服务器提供的展示内容，服务器负责准备展示内容、业务逻辑以及数据访问逻辑，应用程序的数据来自企业信息系统，例如关系数据库。在这样的系统中，业务逻辑可以通过远程访问，因此通过Java控制台应用程序支持一个独立的客户端就成为课程。业务层主要通过数据访问层与信息系统实现交互。因为整个应用都位于服务器之上，因此这样的服务器也被称作&#8220;应用程序服务器&#8221;或者&#8220;中间件&#8221;（参见图3）。</p>
            <p align="center" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 28px; "><a href="http://images.51cto.com/files/uploadimg/20090825/1345192.jpg" target="_blank" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-decoration: underline; color: #0000ff; "><img class="fit-image" height="355" alt="Java企业级应用架构中的3级结构" src="http://images.51cto.com/files/uploadimg/20090825/1345192.jpg" width="551" border="0" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /></a><br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            <font size="2" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">图3. 3级结构（图中文字：Presentation Layer——表现层；Business Logic Layer——业务逻辑层；Data Access Layer——数据访问层；Thin Client——瘦客户端；Application Server——应用程序服务器；Enterprise Data——企业数据；Database Server——数据库服务器）</font></p>
            <p align="left" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 28px; "><strong style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">N级结构<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            </strong>&nbsp;<br style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " />
            随着互联网带宽的不断提高，全世界的各大企业都相继启动了他们的网络服务。这种变化导致应用服务器无法继续承担表现层的巨大负荷。这项任务现在已经由专门负责产生展示内容的专门网页服务器所承担。展示内容之后被传送到客户端级的浏览器上，浏览器会负责将用户接口表现出来。N级结构中的应用服务器负责提供可远程访问的业务逻辑组件，而表现层网页服务器则使用本网协议通过网络访问这些组件。图4展示了n级结构。</p>
            <p align="center" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 28px; "><a href="http://images.51cto.com/files/uploadimg/20090825/1345193.jpg" target="_blank" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; text-decoration: underline; color: #0000ff; "><img class="fit-image" height="312" alt="Java企业级应用架构中的N级结构" src="http://images.51cto.com/files/uploadimg/20090825/1345193.jpg" width="599" border="0" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; " /></a>&nbsp;</p>
            <p align="left" style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; text-indent: 28px; ">以上是Java企业级应用架构设计中的分布式结构，在不同的需求和应用场景中，我们会用到不同的分布式结构，设计不同的Java企业级应用架构。</p>
        </ul>
        <p>&nbsp;</p>
    </ul>
    </span>
<img src ="http://www.blogjava.net/masen/aggbug/321913.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/masen/" target="_blank">Masen</a> 2010-05-26 15:17 <a href="http://www.blogjava.net/masen/articles/321913.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>模式与J2EE</title><link>http://www.blogjava.net/masen/articles/128987.html</link><dc:creator>Masen</dc:creator><author>Masen</author><pubDate>Mon, 09 Jul 2007 02:34:00 GMT</pubDate><guid>http://www.blogjava.net/masen/articles/128987.html</guid><wfw:comment>http://www.blogjava.net/masen/comments/128987.html</wfw:comment><comments>http://www.blogjava.net/masen/articles/128987.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/masen/comments/commentRss/128987.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/masen/services/trackbacks/128987.html</trackback:ping><description><![CDATA[<h2>模式与J2EE</h2>
<hr width="95%" color="red" size="1" />
<font size="2">blueski推荐&nbsp;[2005-3-24]</font><br />
<font size="2">出处：来自网上</font><br />
<font size="2">作者：不详</font><br />
<font size="2">&nbsp;<font size="+0"><br />
<br />
<p>信息工程是以当前数据系统为基础，在一个企业或企业的主要部门，关于建设信息系统的规 划、分析、设计和构成的一整套相互关联的正规化、自动化的技术应用。
</p>
<div align="right">--- James Martin&nbsp; </div>
<br />
&nbsp;&nbsp;&nbsp; 正如上面信息工程的创始人James Martin为信息工程的概念所做定义类似，模式(Patterns)的创始人建筑师Christopher Alexander在&lt;模式语言，1977、1979&gt;一书中对模式的概念进行了如下描述(附注：书名后面的年份代表在各个不同时期的作品，下面形式同上)：<br />
每一个模式描述了一个在我们周围不断重复发生的问题，以及该问题的解决方案的核心。这样，你就能一次又一次的使用该解决方案而不必做重复劳动。每个模式是由三部分组成的一个规则，这个规则描述特定环境、问题和解决方案之间的关系。简单的说，没有一个模式是独立的实体，每个模式都存在着相互支持，但支持的程度不同：大的模式可以内嵌小的模式，同等层次的模式并列存在，而小的模式被嵌入到大的模式之中。
<div align="right">--- Christopher Alexander&nbsp;&nbsp; </div>
<p>&nbsp;&nbsp;&nbsp; 模式的概念在软件行业被采用以后，得到的广泛的发展，现在已经存在许多种类型的模式应用，其中比较有名的箸作有：GoF(Erich Gamma、Richard Helm、Ralph Johnson和John Vlissides四人，简称：Gang of Four[GoF])的&lt;设计模式，1995&gt;，Martin Fowler的&lt;分析模式，1997&gt;，Frank Buschmann等人的&lt;体系结构模式，1996、2000&gt;、Jim O.Coplien、Niel Harrison等人的&lt;编程模式，1995、1996、1998、1999&gt;和Deepak Alur等人的&lt;J2EE核心模式，2001&gt;等，其中最具影响的是GoF的&lt;设计模式&gt;一书，书中详细讨论了三种类型，共23种模式。好的设计源于工作中经验的积累，当设计使用标准的模板以模式的方式进行交流时，模式就成了交流和重用的强大机制，并且可以改善设计和开发软件的方式。模式可以帮助我们在一个特定的环境里整理并记录已知的可重现的问题及解决方案，并且通过模式来与他人交流这些知识，这些模式可以解决在不同环境中重复出现的问题。模式可以使设计重复使用，重复使用已知的解决方案可以缩短设计和开发应用的周期，有效的使用模式，可以使我们远离重复投资的怪圈。模式的关键在于简单性和可重现性。<br />
&nbsp;&nbsp;&nbsp; 举一个模式应用的简单示例。例如，在你的便携式电脑上运行一个进程中的对象，并且这些对象需要和运行在另一进程中的别的对象通信，也许这一进程并不在你的便携式电脑上，而在别的地方。你又不想让系统中的对象担心如何找寻网上的其他对象或者执行远程过程调用。这时，可以使用代理(Proxy模式，详见GoF的&lt;设计模式&gt;一书)模式来解决这个问题，你能做的事就是为这个远程对象在你的本地过程中建立一个代理对象，该代理对象和远程对象具有相同的接口。你的本地对象利用通常处理过程中的消息发送来和代理交谈。这时代理对象负责把消息传送给实在对象，而不管实在对象位于何处。<br />
&nbsp;&nbsp;&nbsp; 由于下面要讲的Java 2平台的企业版(J2EE)应用模式中很多用到了设计模式与重构(Refactoring)的概念，所以在此有必要再概要介绍一下重构的概念。重构已经被证明可以阻止软件的腐朽和衰败，关于重构方面的有名箸作当然首推是Martin Fowler所写的&lt;重构，1999&gt;一书了，书中详细介绍了重构的七大类型，共70余种具体的重构手法，同时也指出测试机制在重构中的重要性。书中Martin Fowler对重构的概念进行了详细说明：<br />
&nbsp;&nbsp;&nbsp; 重构是对软件内部结构的一种调整，目地是在不改变[软件之可察行为]的前提下，提高其可理解性，降低其修改成本。重构是一种有纪律的、经过训练的、有条不紊的程序整理方法，可以将整理过程中不小心引入的错误的机率降到最低，本质上说，重构就是在代码写好之后改进它的设计。重构之前，首先检查自己是否有一套可靠的测试机制，这些测试必须有我检验能力。<br />
</p>
<div align="right">--- Martin Fowler&nbsp; </div>
<br />
&nbsp;&nbsp;&nbsp; 建立于Java编程语言和Java技术基础之上的J2EE平台是最适用于企业级分布式环境的应用结构，它被设计为面向多层体系的结构。J2EE包含下面关键技术：Java服务器页面(Java Service Page，JSP)、Servlet、Enterprise JavaBeans(EJB)组件、Java消息服务(Java Message Service，JMS)、JDBC和Java命名与目录接口(Java Naming and Directory Interface，JNDI)。由于J2EE平台是分层系统，所以我们将J2EE的层次模型化，这个模型使得我们将职责逻辑地分到不同的层中，共分了五个层次：客户层、表示层、业务层、集成层和资源层。因为客户层和资源层并不是J2EE平台直接关注的问题，所以后面介绍的15个J2EE应用模式全部属于上面五层中的中间三层，其中表示层模式包含与Servlet和JSP技术相关的模式、业务层模式包含与EJB技术有关的模式、集成层模式包含与JMS和JDBC有关的模式。具体模式可参看下面表格：<br />
<br />
表一：表示层模式
<table id="AutoNumber1" style="border-collapse: collapse; " bordercolor="#111111" cellspacing="0" cellpadding="0" width="89%" border="1">
    <tbody>
        <tr>
            <td align="center" width="50%"><strong>模式名</strong></td>
            <td align="center" width="50%"><strong>简单描述</strong></td>
        </tr>
        <tr>
            <td width="50%">截取过滤器(Intercepting Filter) </td>
            <td width="50%">促进请求的预先处理和后处理</td>
        </tr>
        <tr>
            <td width="50%">前端控制器(Front Controller) </td>
            <td width="50%">提供请求处理的集中控制器</td>
        </tr>
        <tr>
            <td width="50%">视图助手(View Helper) </td>
            <td width="50%">把与表示层格式化无关的逻辑封装到助手组件</td>
        </tr>
        <tr>
            <td width="50%">复合视图(Composite View) </td>
            <td width="50%">从原子的子组件创建一个聚集视图</td>
        </tr>
        <tr>
            <td width="50%">工作者服务(Service To Worker) </td>
            <td width="50%">合并分发者组件、前端控制器和视图助手模式</td>
        </tr>
        <tr>
            <td width="50%">分发者视图(Dispatcher View) </td>
            <td width="50%">合并分发者组件、前端控制器和视图助手模式，把许多动作推迟到视图处理</td>
        </tr>
    </tbody>
</table>
<br />
<br />
表二：业务层模式<br />
<table id="AutoNumber2" style="border-collapse: collapse; " bordercolor="#111111" cellspacing="0" cellpadding="0" width="90%" border="1">
    <tbody>
        <tr>
            <td align="center" width="50%"><strong>模式名</strong></td>
            <td align="center" width="50%"><strong>简单描述</strong></td>
        </tr>
        <tr>
            <td width="50%">业务委托(Business Delegate) </td>
            <td width="50%">把表示层和服务层分隔开，并且提供服务的外观和代理接口</td>
        </tr>
        <tr>
            <td width="50%">值对象(Value Object) </td>
            <td width="50%">通过减少网络对话，以加速层之间的数据交换</td>
        </tr>
        <tr>
            <td width="50%">会话外观(Session Facade) </td>
            <td width="50%">隐藏业务对象复性，集中化工作流处理</td>
        </tr>
        <tr>
            <td width="50%">复合实体(Composite Entity) </td>
            <td width="50%">通过把参数相关的对象分组进单个实体bean，表示设计粗粒度实体bean的最好经验</td>
        </tr>
        <tr>
            <td width="50%">值对象组装器(Value Object Assembler) </td>
            <td width="50%">把来自多个数据源的值对象组装成一个复合值对象</td>
        </tr>
        <tr>
            <td width="50%">值列表处理器(Value List Handler) </td>
            <td width="50%">管理查询执行、结果缓冲、以及结果处理</td>
        </tr>
        <tr>
            <td width="50%">服务定位器(Service Locator) </td>
            <td width="50%">封装业务服务查找和创建的复杂性，定位业务服务工厂</td>
        </tr>
    </tbody>
</table>
<br />
<br />
表三：集成层模式<br />
<table id="AutoNumber3" style="border-collapse: collapse; " bordercolor="#111111" cellspacing="0" cellpadding="0" width="91%" border="1">
    <tbody>
        <tr>
            <td align="center" width="50%"><strong>模式名</strong></td>
            <td align="center" width="50%"><strong>简单描述</strong></td>
        </tr>
        <tr>
            <td width="50%">数据访问对象(Data Access Object) </td>
            <td width="50%">抽象数据源，提供对数据的透明访问</td>
        </tr>
        <tr>
            <td width="50%">服务激发器(Service Activator) </td>
            <td width="50%">加速EJB组件的异步处理</td>
        </tr>
    </tbody>
</table>
<p>&nbsp;&nbsp;&nbsp; 由于J2EE模式众多，篇幅有限，这里只概要介绍其中的一种应用模式 - 集成层的数据访问对象(DAO)模式，有兴趣的读者可以参看下面参考文献中的资料。<br />
数据访问对象模式<br />
<br />
<img src="http://www.sawin.cn/doc/share/324734.gif"  alt="" /> 数据访问对象模式<br />
<br />
1、问题<br />
&nbsp;&nbsp;&nbsp; 根据数据源不同，数据访问也不同。根据存储的类型(关系数据库、面向对象数据库等)和供应商不同，持久性存储(比如数据库)的访问差别也很大。当业务组件(如会话bean)或表示组件(如助手组件)需要访问某数据源时，它们可以使用合适的API来获得连接性，以及操作该数据源。但是在这些组件中包含连接性和数据访问代码会引入这些组件及数据源实现之间的紧密耦合。组件中这类代码依赖性使应用程序从某种数据源迁移到其它种类的数据源将变得非常麻烦和困难，当数据源变化时，组件也需要改变，以便于能够处理新类型的数据源。<br />
<br />
2、解决方案<br />
&nbsp;&nbsp;&nbsp; 使用数据访问对象(DAO)来抽象和封装所有对数据源的访问。DAO管理着与数据源的连接以便于检索和存储数据，DAO实现了用来操作数据源的访问机制。依赖于DAO的业务组件为其客户端使用DAO提供了更简单的接口，DAO完全向客户端隐藏了数据源实现细节。由于当低层数据源实现变化时，DAO向客户端提供的接口不会变化，所以该模式允许DAO调整到不同的存储模式，而不会影响其客户端或业务组件。重要的是，DAO充当组件和数据源之间的适配器。<br />
<br />
3、实现策略<br />
&nbsp;&nbsp;&nbsp; 通过调整抽象工厂(Abstract Factory)模式和工厂方法(Factory Method，这二个创建型模式的实现详情可参看GoF的&lt;设计模式&gt;一书)模式，DAO模式可以达到很高的灵活度。
</p>
<ul>
    <li>当低层存储不会随着实现变化而变化时，可以使用工厂方法模式来实现该策略，以产生应用程序需要的大量DAO，如下面类图1所示。
    </li>
    <li>当低层存储随着实现的变化而变化时，策略可以通过使用抽象工厂模式而实现。抽象工厂可以基于工厂方法实现而创建，并可使用工厂方法实现，该策略提供一个DAO的抽象工厂对象，其中该对象可以构造多种类型的具体的DAO工厂，每个工厂支持一种不同类型的持久性存储实现。一旦你获取某特定实现的具体DAO工厂，你可以使用它来生成该实现中所支持和实现的DAO，如下面类图2所示。 <br />
    <br />
    <br />
    <img src="http://www.sawin.cn/doc/share/324822.jpg" border="0"  alt="" /> </li>
</ul>
<br />
4、应用<br />
&nbsp;&nbsp;&nbsp; 当数据访问代码被直接嵌入到有其他不相关职责的某类中时，就会使修改变的十分困难。这时可以采用分离数据访问代码的解决方案，将数据访问代码抽取到一个新类中，并且把该新类逻辑或者物理地移动到离数据源比较近的位置，这样可以增强模块性和可重用性，如下面图3所示。具体作法可以使用提炼类(Extract Class，一种重构手法，细节可参看Martin的&lt;重构&gt;一书)方法创建一个新类，并将原来类中把数据访问代码移动到这个新的数据访问对象(DAO)类，使用这个新的DAO对象从控制器类中访问数据。<br />
&nbsp;&nbsp;&nbsp; 示例：持久性逻辑被嵌入到一个使用新DAO对象管理的持久性的某企业新DAO对象中，把持久性代码和该企业新DAO对象代码结合起来会创建脆弱的、紧密耦合的代码。当持久性代码是该企业新DAO对象的一部分时，对该持久性存储的任何改动都要求更改该新DAO对象的持久性代码。这种耦合对企业新DAO对象代码维护会带来负面的影响。下面图4为运用分离数据访问对象方法对其进行重构改进后的结果。<br />
<br />
<br />
<img src="http://www.sawin.cn/doc/share/324830.jpg" border="0"  alt="" /><br />
&nbsp;&nbsp;&nbsp; 在15个J2EE模式中，每个模式都作用于设计模式和构架模式之间的某些方面。每个模式不是孤立存在的，需要其它模式的支持才能更加体现其含义和用处，为了最大限度的用好模式，还需要充分理解模式之间的关系。 <br />
<br />
<img src="http://www.sawin.cn/doc/share/324734.gif"  alt="" /> 参考文献
<p>&nbsp;</p>
<ul>
    <li>系统分析员教程 --- 罗晓沛等箸
    </li>
    <li>设计模式：可复用面向对象软件的元素 --- 李英军等译
    </li>
    <li>重构-改善既有代码的设计 --- 侯捷等译
    </li>
    <li>J2EE核心模式 --- 牛志奇等译
    </li>
    <li>UML精粹(第二版) --- 徐家福译</li>
</ul>
<p>&nbsp;</p>
<!--here is the bottom-->
<p>&nbsp;</p>
</font></font>
<img src ="http://www.blogjava.net/masen/aggbug/128987.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/masen/" target="_blank">Masen</a> 2007-07-09 10:34 <a href="http://www.blogjava.net/masen/articles/128987.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>