Google

Friday, November 18, 2005

Core J2EE patterns: Business Delegate

Context: The client does remote method invocation and is exposed to the complexity of the underlying business service implementation

Problem

1. Different clients need to access business services.
2. The client is exposed to the implementation of the business service.
3. If the service implementation is modified, the client is also affected.
4. Unncessary network communcation (too many invocation perhaps)

Lets take an example where we try to take care of the above mentioned problems.

The client lets say a swing client needs to invoke a remote method.
We can follow the following strategy.

1.Swing class lets say AccountUpdateServerCommand, needs to invoke a AccountUpdateSLSBean.update(some information)

We will write the following classes:
a. AccountUpdateBD
b. JNDIHelper
c. BusinessServiceFactory

2. AccountUpdateBD is the business delegate for the AccountUpdateSLSBean.

3. The AccountUpdateBD and the AccountUpdateSLSBean lets say implement IAccountUpdate interface.

4. Now, AccountUpdateServerCommand invokes BusinessServiceFactory to get reference to the AccountUpdate.

5. BusinessServiceFactory will instantiate the AccountUpdateBD class and return the interface reference.

6. AccountUpdateServerCommand gets back is the IAccountUpdate reference to the AccountUpdateBD instead of the AccountUpdateSLSBean.

7. AccountUpdateServerCommand invokes IAccountUpdate.update() method.

8. AccountUpdateBD.update()will use JNDIHelper to get the remote reference to the AccountUpdateSLSBean. JNDIHelper will make a lookup and return the reference.

9. AccountUpdateBD.update()will then invoke the update method on that reference and return the value to the AccountUpdateServerCommand class.

uses
Client ----------> BusinessDelegate-------------> Business Service
^
lookup/create
Look up service -------------------


Benefits

1. Reduces coupling between the client and the business service

any changes in the service implementation donot affect the client. No changes required in the client.

2. Translates business service exceptions.

Business delegate can handle system exceptions and throw application exceptions to the client.

3. Failure recovery

Business Delegate can have automated failure recovery.

4. Performance

Business Delegate improves performance. It can cache the service references.

5. Hides remeoteness

The client programmer does not to know the details of how to connect to the business service. It provides location transparency and hides the dirty details.

1 Comments:

Blogger Biplav said...

how to do packaging in java.. plz help.. the class file is created in the same folder only.. so wats the purpose of packaging

2:52 PM  

Post a Comment

<< Home