Hello,

Talking about inheritance with EJB, I want to make a question and a design
suggestion:

        -The suggestion: If we have several EJB all of them with the same methods,
but with different behaviour, I think he solution is really simple: the same
remote and home interface classes for all the EJB and different bean classes
for each one. An example (Pedro Garcia's example): let the abstract class P
with method hello(), and A,B,C inheriting from it --they DO NOT add another
method, they only redefine the behaviour of hello(); then I think we have to
make a remote interface (called PRemote), a home interface (called PHome),
three bean classes (ABean, BBean, CBean) and deploy A,B,C beans saying that
their home and remote interfaces are PHome and PRemote (resp.). This method
let you the client use home and remote methods without knowing exactly the
subtype... (of course, you must especify the EJB you want to access in
Context.lookup() method):
                Object obj = ctx.lookup("BBean");               // ...or CBean or ABean
                PHome home = (PHome) ...narrow(obj,PHome.class);
                PRemote remote = home.create();                 // for example
                Enumeration enum = home.findByXXXX(xx);         // and we have an enum 
of
PRemote,
                                                                        // with BBeans 
references.

   PHome            PRemote               PBean
                                            ^
                                            |
                                       +----+----+
                                     ABean BBean CBean


If we add one or more methods to classes A,B or C, remote interface must
change, and therefore, the home interface too. We can reproduce the
hierarchy with remote intefaces (but not with home interfaces: they have the
same method create() signature with different return type). In our case,
AHome, BHome and CHome represent home interfaces; ARemote, BRemote, CRemote
represent remote interfaces, all of them inherit from PRemote; ABean, BBean,
CBean inherit from PBean.

  PHome                          PRemote                    PBean
                                    ^                         ^
  AHome BHome CHome                 |                         |
                            +-------+-------+           +-----+-----+
                       ARemote   BRemote  CRemote     ABean BBean CBean


        What do you think?

        -The question: Is it really a good practice working with home interfaces
without knowing exactly its subtype? Please, say me some examples where this
practice could be a good solution.

Thanks a lot, gurus. Regards


Luis F. Canals
[EMAIL PROTECTED]


===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to