Friday, February 9, 2007

. What is the need of Remote and Home interface. Why cant it be in one

The home interface is your way to communicate with the container, that is who is responsable of creating, locating even removing one or more beans.The remote interface is your link to the bean, that will allow you to remotely access to all its methods and members.

At run time only we create remote object based on user input in create method(whether to access Wesley or x account)so it is not possible to know exactly user input and what remote object it want only at run time he gives input and based on user input remote object is created so we use Factory pattern while creating Remote object.so if we use Factory pattern we need two things either two class or interfac instance.
1, one instance takes input from user--- this is Home Interface instance
2, Based on input it returns an instance --- this Remote interface instance

RemotInt it1=homeint.create();
RemotInt it2=homeint.create(1,2);
RemotInt it3=homeint.create(1,2,5);

In above example based on user input one remote instance is returned from group of 3

so if we merge home and remote interface ,how will u bind JNDI name with (homeMergeRemote) object ,
only based on user input container creates Remote object so we cannot predict what input he gives and
based on input we create Remote object without object we cannot bind it with JNDI tree.
so we have separate Interface Home and Remote

Basic function of Homeobject is
1. To create Remote object simultaneously container will take bean instance from pool and associates with Remoteobject
2. To delete Remoteobject simultaneously container will disassociate bean instance from remote object, pull the bean instance back to the pool.

so home instance function is just like house keeping i.e creating ,locating,associating and deleteing the remote object.it has nothing do with bean instance or functionalty or business logic where as incase of Remoteobject it access the bean business logic Now it clear that we divide the work so we have two separate interface EJB Home and EJB Remote


SOURCE : www.referjava.com

No comments: