How to implement Session Beans in Business delegate class?
Hi All,
I am neither very familiar with BD nor EJB. So please correct me if anything that I say is wrong.
I am deevloping an EJB2 application. We have different components and each component is a session bean. Now i am trying to implement the BD pattern.
From my understanding the BD class will be in the presentation tier. Now wat I am not clear about is will all the Service beans have its own BD class.
Say I have 2 components Staff and Students or will it be just one BD tat calls up a Service Locater to get the Service bean depending on the type of request.
Thanks
Re: How to implement Session Beans in Business delegate class?
The EJB Layer is composed of Business objects, which are session beans, entity beans and DAOs (Data Access Objects). Working as an entry-point to the EJB Layer, the SessionFacade is a session bean that manages the relationships between numerous BusinessObjects to provide higher-level abstraction to the client.
By employing the SessionFacade, the client is provided with a coarse-grained way to access the EJB Layer. The client uses the SessionFacade instead of dealing with more fine grained components from the EJB Layer.
In summary, the SessionFacade provides a simpler interface to the clients by hiding all the complex interactions between business components. The SessionFacade reduces the number of business objects that are exposed to the client across the service layer over the network. The SessionFacade also prevents the exposure of the underlying business objects directly to the client, keeping the client and the EJB layer loosely coupled.
Re: How to implement Session Beans in Business delegate class?
Definitively a normal java class.
The goals of the business delegates are :
1 - Delegate method calls to EJB (that why the pattern has this name, clever, no )
2 - Hide EJB complexity (remote exception and EJB specific stuff)
3 - Decouple the client layer from the business layer
You cannot achieve these goals with an EJB. So you're business delegate must ba a plain java object.
The usual architecture is :
Client --> Business Delegate --> EJB Session Facade --> EJBs (Session or entity)
Re: How to implement Session Beans in Business delegate class?
Business Delegate is to reduce coupling between client and business objects. One of the basic example is, if you use a method from business object in your clients, let say in 10 servlets, if the method signature changes on the business object, you have to change in all(10) your client places(ofcourse, IDE can easily refactor it, but it will be complicated if the project is very big). To avoid this, have a layer of classes/interfaces which have the methods corresponding to each business object.
Session Facade is to reduce the number of network calls made from client to business objects. As you said, if you implement the business logic in your Business Delegate layer, you will be making multiple fine grained calls to your business objects to complete a Use Case. Network calls are expensive and must be reduced. So instead of implementing the business logic in clients, implement it in business object layer and send required data as a bundle(coarse grained).