Edward Barrett wrote:
>
> I wonder if someone can suggest how I would model the following within EJBs.
>
> A client can have many investments, some in stocks, some in cash,
> some in other things. Most investments have the same business
> methods and therefore in a normal OO design I would propose an
> Investment interface or super class (depending on how similar the
> functionality implementations were) and sub classes for each
> investment type.
>
> How can I implement using interfaces or inheritance in Entity beans
> - I'm specifically thinking of generic home interfaces, inheritance
> within remote interfaces / stubs, etc.
>
> Or can this just not be done in EJB ?
It can be done--sort of--with some caveats and a couple of tricks.
(First of all, insert obligatory comments about how just because
something is an object doesn't mean it should be an EJB here. Then go
hunt through the archives for messages with "dependent objects" in
them. Finally, if most of your work is read-only, i.e. lots of searches
etc. and you're doing very few transactions then EJB ain't for you.)
As you know, an EJB consists of two "halves". On one half you have the
home and the remote interface. On the other half you have the bean
class. Inheritance can occur within either half, but not "across" them.
Thus you could have an Investment remote interface, and a Stock sub
interface and a Bond sub interface, but you'd also have to mirror that
on the other side--you'd need an InvestmentBean abstract class, a
StockBean class and a BondBean class.
Finally, this only gets you so far because if you say something like
InvestmentHome.findAllInvestments() the collection you get back will NOT
return you any instances of Stock or Bond (as you might otherwise expect
from a good OO language). I regard this as a flaw, but then the problem
*is* rather hairy (for finder methods to behave "properly" you would
have to know all possible subclasses at runtime).
As an addition, note that generic home interfaces such as my
hypothetical InvestmentHome above can't really exist--well, they *can*,
but they won't do what you want for the reasons cited above.
Does that help? Now, once you actually have your hands on a particular
sub-remote-interface of Investment, you can of course pass that
sub-interface to any method you like that takes an Investment as a
parameter, just as you can with plain-jane Java objects.
Cheers,
Laird
===========================================================================
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".