Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Why two interfaces ( home and component ) ?

 
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,
After going through the various types of beans, I get a very basic doubt, why do we have a home interface and a component interface. Why cant there be just one interface that does the work of both.
Like I have so many doubts. Why cant the client get the EJBObject directly rather than going through the EJBHome. I know it works that way but I want to know * WHY ? * What is the need of EJBHome ? Is it just to create a EJBObject and for the finder methods ?
What is the reason that it has been implemented as two interfaces rather than one? Again may seem a silly doubt but I am not able to see the reasoning behind it.
 
Ranch Hand
Posts: 8943
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stateful session beans can take different parameters in its create method.
For example
RemotInt it1=homeint.create();
RemotInt it2=homeint.create(1,2);
RemotInt it3=homeint.create(1,2,5);

If we had a single interface for the home and remote we would have to bind them to 3 different JDNI name for the example above.
[ December 10, 2003: Message edited by: Pradeep Bhat ]
 
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also had this question, a few months ago...
The way I understand is...
J2EE has most of the ideas borrowed from CORBA. With Corba, first you retrieve the server object and then start calling the business methods.
These are 2 different activities one followed by the other...
I guess for modularity reasons, SUN came out with this idea of having 2 different interfaces to be implemented by 2 different Objects on the server side. It is easy thing to say, that we could combine both the functionality into 1 server side object, but I guess it may not be easy at all, for the Vendor to provide such an EJB Container implementation...
If anybody has something else to add, please do...
 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reghu,
It will become more clear when you read about entity beans. Entity beans have more stuff in their Home interface. Also don't forget that for every bean interface class there is only one Home interface object on server (and it always stays in memory). But for every bean class there might be many EJBObjects..
You pass now EJBObject when you want to give someone access to bean. If you would pass EJBHome+EJBObject, that would certainly be overheat.
Then think about server:
a) If instead of EJBObject would be EJBHome+EJBObject.. It's memory waste again. Server always needs only 1 instance of Home interface object.
b) You have to have something on container which is able to create that particular bean for you. Since there might be many EJBObjects for the same bean class.. which one will stay always on server to serve your request to create another one?
From design approach I believe this is correct to separate what belongs to your bean class with what belongs to it's instance. Home belongs to your bean class and Object Interface belongs to particular bean instance.
So keep reading, it will clear up later.
 
Reghu Ram Thanumalayan
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,
I knew that two interfaces are really required in case of Stateful session beans and entity beans.

Then think about server:
a) If instead of EJBObject would be EJBHome+EJBObject.. It's memory waste again. Server always needs only 1 instance of Home interface object.
b) You have to have something on container which is able to create that particular bean for you. Since there might be many EJBObjects for the same bean class.. which one will stay always on server to serve your request to create another one?


But i guess Vladas's explanation answers most of my questions.
Thanks for making it clear guys.
 
Pradeep bhatt
Ranch Hand
Posts: 8943
Firefox Browser Spring Java
 
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic