Context
Enterprise beans encapsulate business logic and business data and expose their
interfaces, and thus the complexity of the distributed services, to the client tier.
Problem
In a multitiered Java 2 Platform, Enterprise Edition (J2EE) application environment,
the following problems arise:
Tight coupling, which leads to direct dependence between clients and business
objects;
Too many method invocations between client and server, leading to network
performance problems;
Lack of a uniform client access strategy, exposing business objects to misuse.
A multitiered J2EE application has numerous server-side objects that are
implemented as enterprise beans. In addition, some other arbitrary objects may provide
services, data, or both. These objects are collectively referred to as business objects, since
they encapsulate business data and business logic.
J2EE applications implement business objects that provide processing services as
session beans. Coarse-grained business objects that represent an object view of persistent
storage and are shared by multiple users are usually implemented as entity beans.
Application clients need access to business objects to fulfill their responsibilities and
to meet user requirements. Clients can directly interact with these business objects because
they expose their interfaces. When you expose business objects to the client, the client must
understand and be responsible for the business data object relationships, and must be able to
handle business process flow.
However, direct interaction between the client and the business objects leads to tight
coupling between the two, and such tight coupling makes the client directly dependent on
the implementation of the business objects. Direct dependence means that the client must
represent and implement the complex interactions regarding business object lookups and
creations, and must manage the relationships between the participating business objects as
well as understand the responsibility of transaction demarcation.
As client requirements increase, the complexity of interaction between various
business objects increases. The client grows larger and more complex to fulfill these
requirements. The client becomes very susceptible to changes in the business object layer;
in addition, the client is unnecessarily exposed to the underlying complexity of the system.
Tight coupling between objects also results when objects manage their relationship
within themselves. Often, it is not clear where the relationship is managed. This leads to
complex relationships between business objects and rigidity in the application. Such lack of
flexibility makes the application less manageable when changes are required.
When accessing the enterprise beans, clients interact with remote objects. Network
performance problems may result if the client directly interacts with all the participating
business objects. When invoking enterprise beans, every client invocation is potentially a
remote method call. Each access to the business object is relatively fine-grained. As the
number of participants increases in a scenario, the number of such remote method calls
increases. As the number of remote method calls increases, the chattiness between the client
and the server-side business objects increases. This may result in network performance
degradation for the application, because the high volume of remote method calls increases
the amount of interaction across the network layer.
A problem also arises when a client interacts directly with the business objects. Since
the business objects are directly exposed to the clients, there is no unified strategy for
accessing the business objects. Without such a uniform client access strategy, the business
objects are exposed to clients and may reduce consistent usage.
Forces
Provide a simpler interface to the clients by hiding all the complex interactions
between business components.
Reduce the number of business objects that are exposed to the client across the
service layer over the network.
Hide from the client the underlying interactions and interdependencies between
business components. This provides better manageability, centralization of interactions
(responsibility), greater flexibility, and greater ability to cope with changes.
Provide a uniform coarse-grained service layer to separate business object
implementation from business service abstraction.
Avoid exposing the underlying business objects directly to the client to keep tight
coupling between the two tiers to a minimum.
Solution
Use a session bean as a facade to encapsulate the complexity of interactions between
the business objects participating in a workflow. The Session Facade manages the business
objects, and provides a uniform coarse-grained service access layer to clients.
The Session Facade abstracts the underlying business object interactions and provides
a service layer that exposes only the required interfaces. Thus, it hides from the client's view
the complex interactions between the participants. The Session Facade manages the
interactions between the business data and business service objects that participate in the
workflow, and it encapsulates the business logic associated with the requirements. Thus, the
session bean (representing the Session Facade) manages the relationships between business
objects. The session bean also manages the life cycle of these participants by creating,
locating (looking up), modifying, and deleting them as required by the workflow. In a
complex application, the Session Facade may delegate this lifestyle management to a
separate object. For example, to manage the lifestyle of participant session and entity beans,
the Session Facade may delegate that work to a Service Locator object (see "Service
Locator" on page 368).
It is important to examine the relationship between business objects. Some
relationships between business objects are transient, which means that the relationship is
applicable to only that interaction or scenario. Other relationships may be more permanent.
Transient relationships are best modeled as workflow in a facade, where the facade manages
the relationships between the business objects. Permanent relationships between two
business objects should be studied to determine which business object (if not both objects)
maintains the relationship.
Use Cases and Session Facades
So, how do you identify the Session Facades through studying use cases? Mapping
every use case to a Session Facade will result in too many Session Facades. This defeats the
intention of having fewer coarse-grained session beans. Instead, as you derive the Session
Facades during your modeling, look to consolidate them into fewer numbers of session
beans based on some logical partitioning.
For example, for a banking application, you may group the interactions related to
managing an account into a single facade. The use cases Create New Account, Change
Account Information, View Account information, and so on all deal with the coarse-grained
entity object Account. Creating a session bean facade for each use case is not recommended.
Thus, the functions required to support these related use cases could be grouped into a
single Session Facade called AccountSessionFacade.
In this case, the Session Facade will become a highly coarse-grained controller with
high-level methods that can facilitate each interaction (that is, createNewAccount,
changeAccount, getAccount). Therefore, we recommend that you design Session Facades to
aggregate a group of the related interactions into a single Session Facade. This results in
fewer Session Facades for the application, and leverages the benefits of the Session Facade
pattern.
- 浏览: 15492 次
- 性别:
- 来自: 北京
文章分类
最新评论
发表评论
-
集成层模式:Service Activator—服务激发器模式
2014-04-09 20:31 1116ContextEnterprise beans and o ... -
集成层模式:Data Access Object—数据访问对象模式
2014-04-09 20:31 539ContextAccess to data varies ... -
业务层模式:Service Locator—服务定位器模式
2014-04-09 20:31 1174ContextService lookup and cre ... -
表示层模式:Value List Handler—值列表处理器模式
2014-04-09 20:32 775ContextThe client requires a ... -
表示层模式:Transfer Object Assembler—传输对象组装器模式
2014-04-10 22:48 768ContextIn a Java 2 Platform, ... -
业务层模式:Composite Entity—复合实体模式
2014-04-08 21:38 505ContextEntity beans are not i ... -
业务层模式:Transfer Object—传输对象模式
2014-04-08 21:37 438ContextApplication clients ne ... -
业务层模式:Business Delegate—业务委托模式
2014-04-08 21:37 989ContextA multi-tiered, distri ... -
表示层模式:Dispatcher View—分发者视图模式
2014-04-08 21:37 548ContextSystem controls flow o ... -
表示层模式:Service to Worker—工作者服务模式
2014-04-07 10:48 993ContextThe system controls flow ... -
表示层模式:Front Controller—前端控制器模式
2014-04-07 10:45 383ContextThe presentation-tier re ... -
表示层模式:Composite View—复合视图模式
2014-04-07 10:41 492ContextSophisticated Web page ... -
表示层模式:View Helper—视图助手模式
2014-04-07 10:37 1036ContextThe system creates pre ... -
表示层模式:Intercepting Filter—拦截过滤器模式
2014-04-07 10:29 630Context The presentati ...
相关推荐
1. **会话门面**:Laravel提供了一个名为`Session`的门面,它简化了对Session的操作。例如,`Session::put('key', 'value')`等同于`session(['key' => 'value'])`。 2. **会话操作链式调用**:通过门面,你可以执行...
- **Session Facade Pattern**: 创建一个简单的会话Bean作为其他复杂Bean的门面,提供一个统一的接口供客户端调用。 - **Business Delegate Pattern**: 用于将远程对象的复杂性隐藏起来,提供一个轻量级的本地代理...
- ** Session Facade模式**:在客户端和EJB组件之间提供一个单一的会话接口,隐藏后端复杂的业务逻辑。 - ** Front Controller模式**:用于处理所有的请求,如Servlet的DispatcherServlet,它负责调度请求。 - ** ...
6. **设计模式**:SSO系统通常采用门面(Facade)或代理(Proxy)模式来隐藏内部复杂性,提供简洁的API供各个子系统调用。这有助于保持系统的可维护性和扩展性。 7. **异常处理与日志记录**:在实现SSO过程中,确保...
- **SecurityManager**:作为Shiro的门面(Facade),它统一管理所有与安全相关的操作,包括认证、授权、会话管理和密码加密。它是Shiro的核心,通过它来调用其他组件的功能。 - **Authenticator**:负责处理“你是...
- **SecurityManager**:作为门面(Facade),Shiro通过此组件向外部提供安全管理的各项服务。 - **Authenticator**:负责验证用户身份,即解决“你是谁”这一问题。主要涉及用户名与密码的匹配过程。 - **...
开发者需要通过Laravel提供的Session门面(facade)来操作Session数据。 代码部分演示了如何在控制器中设置和获取Session数据。`Session::put`用于设置Session值,`Session::get`用于获取Session值,而`Session::...
2. **会话门面(Session Facade)**:提供了一个简单的接口来访问复杂的业务逻辑,隐藏了底层实现细节。 3. **数据访问对象(Data Access Object, DAO)**:用于封装对数据库的访问操作,使得业务逻辑层无需直接与...
SLF4J(Simple Logging Facade for Java)则是一个日志门面(Logging Facade),它为各种日志框架如 Log4j、Logback 提供了一个简单的统一接口。slf4j-api-1.7.24.jar 文件包含了 SLF4J 的 API,允许开发者编写与...
Session Bean 还可以再细分为 Stateful Session Bean 与 Stateless Session Bean ,这两种的 Session Bean都可以将系统逻辑放在 method之中执行,不同的是 Stateful Session Bean 可以记录呼叫者的状态,因此通常...
3. **slf4j-api-1.7.5.jar**:简单日志门面(Simple Logging Facade for Java),为各种日志框架提供一个抽象层,允许最终用户在部署其应用时使用期望的日志系统。Shiro通过SLF4J接口与具体的日志实现(如log4j)...
同时,文档也提到了如何处理系统事件消息,包括使用门面控制器(Facade Controller)或会话控制器(Session Controller)等不同的设计选择。 此外,文章还强调了在软件设计中应该遵循的一些原则,比如低耦合和高内...
SLF4J(Simple Logging Facade for Java)是一个日志门面,需要与特定的日志实现(如log4j、logback)一起使用。解决方法是在类路径中添加一个SLF4J实现的JAR包,比如`slf4j-nop.jar`(无操作日志)、`slf4j-simple....
2. **SecurityManager**:SecurityManager 是 Shiro 的核心组件,它扮演着门面(Facade)的角色,负责管理和协调 Shiro 的其他组件。它管理着 Authenticator、Authorizer、SessionManager 和 CacheManager 等,为...
2. **使用门面**:在控制器、视图、模型等各个层面上,可以合理地使用门面来简化代码,如使用`Session`门面处理用户会话,使用`Request`门面获取请求数据。 3. **依赖注入**:在类的构造函数中声明依赖,让服务容器...
Laravel Facade 提供了一个方便的接口来访问框架的核心服务,通过 Facade 实现了门面模式,使得开发者可以使用静态方法调用而无需实例化对象。Ioc(控制反转)容器是 Laravel 的核心组件之一,负责管理对象的生命...
6. `slf4j-api-1.5.8.jar` 和 `slf4j-log4j12-1.5.8.jar`: Simple Logging Facade for Java (SLF4J) 是一个日志门面,允许开发者选择不同的日志实现。`slf4j-log4j12.jar` 是SLF4J与Log4j之间的桥接器,使得...