DekGenius.com
[ Team LiB ] Previous Section Next Section

B.4 Business Tier Interface Patterns

Business Delegate

Goal

Encapsulates knowledge of how to locate, connect to, and interact with business objects in the presentation tier (Figure B-7).

Figure B-7. Classes in the Business Delegate pattern
figs/j2ee_ab07.gif

Participants

Client

Manipulates business tier data using a delegate. Usually part of the presentation tier's model.

Business delegate

Locates, connects to, and interacts with business services.

Business service

Controls access to business objects.

Business objects

Store business data.

Interactions

A client calls a business method of the business delegate. The delegate locates the correct business service and connects to it. The business service grants the business delegate access to the relevant business objects. The business delegate manipulates the business objects and returns the result to the client.

Notes

Business delegates are part of the client's data model, not the business tier. In non-EJB implementations, delegates often use service adapters to connect to business services. In an EJB implementation, delegates may perform JNDI lookups and manipulate EJB home objects directly, or may use service locators or data access objects.

Business delegates may be stateful or stateless. Business delegates may also be nested, allowing one delegate to use other delegates.

Business Delegate Factory

Goal

Simplify instantiation and configuration of business delegates.

Participants

Client

Manipulates business tier data using a delegate.

Business delegate factory

Configures and instantiates business delegates.

Business delegates

Locate, connect to, and interact with business services (Figure B-8).

Figure B-8. Interactions in the Business Delegate Factory pattern
figs/j2ee_ab08.gif

Interactions

A client creates a new instance of a business delegate factory. The client sets attributes of the factory that control the type and options of the desired delegate. The factory generates a new instance of the requested delegate with the relevant parameters and returns it to the client. The client uses the delegate to interact with the business tier.

Notes

A business delegate factory may be stateful or stateless. If the factory is stateless, each call must contain all the required configuration parameters, but the factory can be a singleton.

Service Adapter

Goal

Simplify access to remote business data by adapting the data into Java objects.

Participants

Client

Manipulates business data using an adapter.

Service adapter

Adapts business data into a convenient Java implementation.

Business service

Stores and controls access to business data (Figure B-9).

Figure B-9. Interactions in a SOAP service adapter
figs/j2ee_ab09.gif

Interactions

The client creates and initializes the service adapter. The client requests business data from the adapter, passing in Java objects as arguments. The adapter connects to the remote service using an appropriate protocol and translates any arguments to the correct form. The adapter receives the results and translates them into Java objects, which are returned to the client.

Notes

Service adapters are most useful when business data is stored in a non-Java format. Adapters may also be used to impose desired semantics such as transactions onto services. For EJBs, service locators are usually more appropriate than service adapters.

Service Locator

Goal

Simplify and centralize connections to remote services (Figure B-10).

Figure B-10. Classes in the Service Locater pattern
figs/j2ee_ab10.gif

Participants

Client

Locates business services using a service locator.

Service locator

Looks up and maintains connections to remote service factories.

Service factory

Instantiates business services.

Business services

Control access to business data (Figure B-11).

Figure B-11. Interactions in the Service Locator pattern
figs/j2ee_ab11.gif

Interactions

The client instantiates and configures the service locator. The client requests a remote service factory from the locator. The locator looks up and optionally caches the service factory. The client uses the factory to generate an instance of the business service. The client uses the business service to manipulate business data.

Notes

In J2EE, service locators can be used to encapsulate interactions with the JNDI directory. The service factories are EJB home objects, or JMS connection factories. EJB service locators frequently cache results of JNDI lookups such as EJB home objects.

Session Façade

Goal

Increase performance by organizing remote business data in the most efficient manner (Figure B-12).

Figure B-12. Classes in the Session Façade pattern
figs/j2ee_ab12.gif

Participants

Client

Manipulates business data using a façade.

Session façade

Remote object that provides access to business data.

Business objects

Stores business data (Figure B-13).

Figure B-13. Interactions in the Session Façade pattern
figs/j2ee_ab13.gif

Interactions

The client calls a business method of the remote session façade. The façade locates and manipulates business objects locally and returns the result to the client.

Notes

Session façades are most effective when using Session EJBs and EJB local home objects. This combination allows the façade to manipulate EJBs locally, significantly reducing network overhead. Façades usually communicate with clients using DTOs.

    [ Team LiB ] Previous Section Next Section