• Post Reply Bookmark Topic Watch Topic
  • New Topic

Diffrence between narrowing and casting

 
Hari babu
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When we get the remote reference we narrow the reference to the remote interface. Why is the narrowing done and how is it diffrent from object casting ?
 
Rahul JG
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the prime differences between EJB1.0 and EJB1.1 is EJB1.1 uses RMI-IIOP. Now, IIOP is not specific to a particular language. Many of the languages that IIOP supports (for ex: COBOL) do not have the concept of inheritance or polymorphism, so explicit Java casting is out of question.
However converting a more general interface to a more specific interface is necessary in object oriented programming. In CORBA this is achieved by the PortableRemoteObject which abstracts the mechanism in a protocol independent manner.
What PortableRemoteObject.narrow() returns is the stub that implements the remote interface. Since this stub is known to implement the correct type, you can now use Java's casting mechanism to cast if to the correct interface.
This is why you could use direct casting in EJB1.0 but not in EJB1.1
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!