J2EE Design Pattern : Business Tier Patterns : Business Delegate Design Pattern
Business Delegate Design Pattern? |
Business Delegate decouples presentation and service tiers, and provides a facade and proxy interface to the services.
Typically, Web Client directly acessing a business object, Such as EJB needs to implement the client-side API of the Business Object.
The Web Client also needs to perform the necessary lookup to locate the business object to access them.
As a result, Any changes in the implementation of the business object results in the change of all the web clients that accesses it.
The business delegate design pattern provides a solution to this problem by introducing business delegate object. The business delegate object encapsulates the logic to access business object from the web client.
The Web Client remains transparent of how the business object is implemented and only interacts locally with the business delegate object.
Problem
The client classes using a remote API will change when the API interfaces change.
Clients interact directly with the business service interface. This means that when the business service code changes, the client code might need to be changed.
Context
The business delegate pattern provides solutions to recurring problems. The common problems while developing J2EE applications and how these problems are solved using patterns are detailed here.
Solution
Use a Business Delegate to encapsulate access to a business service. The Business Delegate hides the implementation details of the business service, such as lookup and access mechanisms.
The intermediate business delegate class separates the business components from the classes that use them.
Business Delegate Class Diagram
The client asks the BusinessDelegate component to provide access to the underlying business service. The BusinessDelegate uses a ServiceLocator to locate the required BusinessService component.
Participants and Responsibilities
BusinessDelegate
The BusinessDelegate’s role is to provide control and protection for the business service. The BusinessDelegate can expose two types of constructors to clients:
- A default constructor to instantiate the BusinessDelegate.
- A constructor to instantiate the BusinessDelegate with an ID as an argument, where ID is a string representation of the reference to a remote object, such as EJBHome or EJBObject.
ServiceLocator
The ServiceLocator is a role fulfilled by a Service Locator implementation. The ServiceLocator encapsulates the implementation details of locating a BusinessService component.
BusinessService
The BusinessService is a business-tier component, such as an enterprise bean, that is being accessed by the client. The component is typically implemented as a Session Façade or a JMS component.
Example for Business Delegate |
Recent Comments