• Post Reply Bookmark Topic Watch Topic
  • New Topic

Silly Question asked in an Interview  RSS feed

 
Bish Ach
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
an any one tell me why we dont ipmlement EJB Remote Interface in the bean class? if we do what will happen?
Thnx in Advance
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I dont think, it is a silly question! Infact, it would probabley be one of the first questions that springs up in your mind when u start studying EJB's
Anyway, from what I know. The calls to the EJBs are routed through the EJB container. That's how container is able to provide many services without any coding on the developer's part. and If you directly implement the remote interface, it may interfere with the Container's routing the remote call the way it wants.
I hope, that wasnt too far away from the correct answer
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sonny pretty much nailed it. The catch is that the container doesn't expose the implementation class over RMI, it exposes a wrapper/proxy which eventually delegates invocations to the implementation class.
 
Rashmi Tambe
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't a silly question, rather a very good question.
EJB specification advises against the practice of directly implementing remote/local interface by the bean class. This is primarily because,
-Remote/local interface extends javax.ejb.EJBObject or javax.ejb.EJBLocalObject resp. Ehese interfaces define extra methods like isIdentical(), getPrimatyKey() etc. which are meant to be implemented by EJBObject or EJBLocalObject stubs and not by bean class.
-If the bean directly implements the remote/local interface, the bean could be directly cast to one of these interfaces allowing the developer to pass an instance of this to client. This is not allowed by the EJB spec.
Therefore, to help managing the compile time consistency between remote/local interface and the bean, business interface design pattern is used. This is well explained in EJB design pattern book by Floyd Marinescu that is available on theserverside.com
[ December 09, 2003: Message edited by: Rashmi Tambe ]
 
Bish Ach
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnx Rashmi for giving me a wonderful explanation.
 
Rashmi Tambe
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome Bish !
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I too agree. A good question..
The same explanation has been given in Ed Roman's book also.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd just like to add that the compiler cannot complain if your bean does implement the Remote interface, as it is accessible (being both public and implicitly static). But is it a bad idea as explained by others: you can then pass a remote reference stub to the client, thus breaking a basic EJB principle that a client never has direct access to a bean.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!