I would like to know why we have home and remote interfaces in EJB. Can't we achieve the same functionality with a single class?
A short fast answer would be �because J2EE is silly� or maybe �because J2EE specifications were written by people that are brilliant technical minds but they lack simplicity, flexibility and easy marketing going�. However the reason, the original idea was that the home interface is kind of object creation factory. Imagine the container that needs to pool all these bean instances. Now you have to connect your clients to one of them. Obviously your client needs a way to identify an instance in the pool. A single unique RMI interface won�t going to help. Look at the RMI for example: there is the server and the client that implements the same interface, the server listens at a specified port number, etc. No instance pooling in this case, just a many-to-one relationship between the clients and the server component. Well ejb wants to improve this concept and therefore introduced the instance pooling and home interfaces. The real question actually is: did it improve that much by using bean instance pooling? A closer look, deeper analyzes and basic profiling tools might show and prove that it actually didn�t. Regards.
Originally posted by Kunal Verma: Can't we achieve the same functionality with a single class?
Ofcourse, you can. You can also, go ahead and write a complex application with a single class. But isn't it better to split up things based on their responsibilities? The home interface, is used to interact with the container (creating bean, locating etc), where as the remote interface is used to interact with the bean . As you can see, the roles they play are different, and hence they are seperate.
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop