`

业务层模式:Business Delegate—业务委托模式

阅读更多

Context
A multi-tiered, distributed system requires remote method invocations to send and
receive data across tiers. Clients are exposed to the complexity of dealing with distributed
components.
Problem
Presentation-tier components interact directly with business services. This direct
interaction exposes the underlying implementation details of the business service
application program interface (API) to the presentation tier. As a result, the presentation-tier
components are vulnerable to changes in the implementation of the business services: When
the implementation of the business services change, the exposed implementation code in the
presentation tier must change too.
Additionally, there may be a detrimental impact on network performance because
presentation-tier components that use the business service API make too many invocations
over the network. This happens when presentation-tier components use the underlying API
directly, with no client-side caching mechanism or aggregating service.
Lastly, exposing the service APIs directly to the client forces the client to deal with
the networking issues associated with the distributed nature of Enterprise JavaBeans (EJB)
technology.
Forces
Presentation-tier clients need access to business services.
Different clients, such as devices, Web clients, and thick clients, need access to
business service.
Business services APIs may change as business requirements evolve.
It is desirable to minimize coupling between presentation-tier clients and the business
service, thus hiding the underlying implementation details of the service, such as lookup
and access.
Clients may need to implement caching mechanisms for business service information.
It is desirable to reduce network traffic between client and business services.
Solution
Use a Business Delegate to reduce coupling between presentation-tier clients and
business services. The Business Delegate hides the underlying implementation details of the
business service, such as lookup and access details of the EJB architecture.
The Business Delegate acts as a client-side business abstraction; it provides an
abstraction for, and thus hides, the implementation of the business services. Using a
Business Delegate reduces the coupling between presentation-tier clients and the system's
business services. Depending on the implementation strategy, the Business Delegate may
shield clients from possible volatility in the implementation of the business service API.
Potentially, this reduces the number of changes that must be made to the presentation-tier
client code when the business service API or its underlying implementation changes.
However, interface methods in the Business Delegate may still require modification if
the underlying business service API changes. Admittedly, though, it is more likely that
changes will be made to the business service rather than to the Business Delegate.
Often, developers are skeptical when a design goal such as abstracting the business
layer causes additional upfront work in return for future gains. However, using this pattern
or its strategies results in only a small amount of additional upfront work and provides
considerable benefits. The main benefit is hiding the details of the underlying service. For
example, the client can become transparent to naming and lookup services. The Business
Delegate also handles the exceptions from the business services, such as java.rmi.Remote
exceptions, Java Messages Service (JMS) exceptions and so on. The Business Delegate may
intercept such service level exceptions and generate application level exceptions instead.
Application level exceptions are easier to handle by the clients, and may be user friendly.
The Business Delegate may also transparently perform any retry or recovery operations
necessary in the event of a service failure without exposing the client to the problem until it
is determined that the problem is not resolvable. These gains present a compelling reason to
use the pattern.
Another benefit is that the delegate may cache results and references to remote
business services. Caching can significantly improve performance, because it limits
unnecessary and potentially costly round trips over the network.
A Business Delegate uses a component called the Lookup Service. The Lookup
Service is responsible for hiding the underlying implementation details of the business
service lookup code. The Lookup Service may be written as part of the Delegate, but we
recommend that it be implemented as a separate component, as outlined in the Service
Locator pattern (See "Service Locator" on page 368.)
When the Business Delegate is used with a Session Facade, typically there is a
one-to-one relationship between the two. This one-to-one relationship exists because logic
that might have been encapsulated in a Business Delegate relating to its interaction with
multiple business services (creating a one-to-many relationship) will often be factored back
into a Session Facade.
Finally, it should be noted that this pattern could be used to reduce coupling between
other tiers, not simply the presentation and the business tiers.

分享到:
评论

相关推荐

    业务代表模式

    业务代表模式(Business Delegate Pattern)用于对表示层和业务层解耦。它基本上是用来减少通信或对表示层代码中的业务层代码的远程查询功能。在业务层中我们有以下实体。 客户端(Client) - 表示层代码可以是 JSP...

    ios app:Delegate例子

    ios app :使用delegate事例

    C#使用委托(delegate)实现在两个form之间传递数据的方法

    本文实例讲述了C#使用委托(delegate)实现在两个form之间传递数据的方法。分享给大家供大家参考。具体分析如下: 关于Delegate【代理、委托】是C#中一个非常重要的概念,向前可以推演到C++的指针,向后可以延续到匿名...

    delegate委托

    从序言中,大家应该对委托和事件的重要性有点了解了吧,虽然说我们现在还是能模糊,但是从我的大白话系列中,我会把这些概念说的通俗易懂的。首先,我们还是先说说委托吧,从字面上理解,只要是中国人应该都知道这个...

    iOS设计模式——委托(delegate)例子

    代码实现代理模式。具体文章简介可以参考博文:http://blog.csdn.net/lovefqing/article/details/8270111

    delegate_it:非 Rails 项目中 ActiveSupport 委托方法的替代品

    #委托 delegate_it gem 提供了一种在非 Rails 项目中使用 ActiveSupport 之类的delegate方法的简单方法。安装在您的 Gemfile 中: gem 'delegate_it'用法 require 'delegate_it'class Cowboy extend DelegateIt attr...

    VB.Net-C#多线程Thread-代理委托delegate编程

    最近收集的VB.Net-C#多线程Thread-代理委托delegate编程。文章列表: c#.net多线程同步.txt C#WebBrowser页面与WinForm交互技巧一.txt C#多线程编程-多细全.txt C#多线程编程简单实例.txt C#多线程窗体控件安全访问....

    委托delegate invoke的简单源代码,适合委托初学者!

    委托delegate invoke的简单源代码,适合委托初学者!

    C++中实现委托(delegate)

    网上有很多关于C++ delegate机制的文章,但都讲的是函数指针的内容,上周就C++中实现C#的delegate机制的问题研究了好几天,查看了很多相关资料,才解决了问题,现将我写的C++ delegate测试程序贴出来,希望能帮到有...

    .Net C#委托 delegate

    本ppt结合场景和实例对C#委托(delegate)的基础进行了讲解:包括了委托的定义,基本语法,同步异步调用,匿名委托的使用,泛型委托,lamda表达式,剖析了委托协变、委托逆变。对委托在.net 3.5框架中的身影进行了分析...

    用Java实现23种设计模式

    业务代表模式(Business Delegate Pattern) 数据访问对象模式(Dao Pattern) 前端控制器模式(Front Controller Pattern) 拦截过滤器模式(Intercepting Filter Pattern) 服务定位器模式(Service Locator ...

    CSharp_Delegate C#委托

    CSharp_Delegate C#委托 本人博客中的示例代码

    ios设计模式delegate

    ios设计模式delegate 示例 ,导航功能的两个视图控制器(用push方式从一个窗口推到另一个窗口),第二个窗口创建两个按钮,标题分别为红色和绿色,点相应的按钮弹回前一个窗口,同时前一个窗口的背影色变成按钮标题...

    rust-delegate:使用较少样板的 Rust 方法委托

    少样板的方法委托 这个 crate 删除了一些结构体的样板,这些结构体只是将它们的一些方法委托给它们的一个或多个字段。 它给你delegate! 宏,它将方法调用委托给选定的表达式(通常是内部字段)。 例子: 通过委托...

    33种JAVA设计模式DEMO

    业务代表模式(Business Delegate Pattern) 组合实体模式(Composite Entity Pattern) 数据访问对象模式(Data Access Object Pattern) 前端控制器模式(Front Controller Pattern) 拦截过滤器模式...

    delegate 委托 示例 代码

    委托的简单理解: 参考了一些资料整合起来 写了个小程序,使您能充分理解和使用————delegate ,委托

    C# 委托(Delegate)

    C# 委托(Delegate) C# 中的委托(Delegate)类似于 C 或 C++ 中函数的指针。委托(Delegate) 是存有对某个方法的引用的一种引用类型变量。引用可在运行时被改变。 委托(Delegate)特别用于实现事件和回调方法。...

    .Net的异步机制(委托Delegate)

    使用.Net 的委托机制来为我们的程序提供异步操作行为. ...public delegate string AsyncEventHandler(string name); 2步,使用委托提供的BeginInvoke, EndInvoke 方法(具体使用下一篇文章详细介绍)来提供异步的调用...

    多线程,Delegate 委托带参数的方法

    Delegate '委托,带参数的方法,多线程,可以轻松在线程中传递参数,获取返回值.

    浅析C# 委托(Delegate)

    C# 中的委托(Delegate)类似于 C 或 C++ 中函数的指针。委托(Delegate) 是存有对某个方法的引用的一种引用类型变量。引用可在运行时被改变。 委托(Delegate)特别用于实现事件和回调方法。所有的委托(Delegate...

Global site tag (gtag.js) - Google Analytics