Suppose you have two EntityBean classes A and B which share some common
functionality and state by inheriting from the same superclass S. Then, if S
has some member variable, say a java.util.Vector called "foos", which is
part of the persistent state of both A and B, my question is this: When
should "foos" be initialized?

I am positive that the ejbCreate methods of A and B could include an
instantiation like "foos = new Vector();" but if I use this model, I have to
remember to write this instantiation into every subclass of S, and if S has
many member variables (and many subclasses) that becomes error prone. - Not
to mention that if I add a new member variable to S I have to modify all
subclasses A, B, etc. to make their ejbCreate(...) instantiate this new
variable.

My own suggestion is to define a method in S, lets call it "void
instantiateS()" and have subclasses A, B, etc. invoke this method in their
ejbCreate(...).
I believe this method should *not* be the (no-arg) constructor of S as I
expect this contructor will be called everytime an instance of A or B is
loaded from persistant storage (which is unnecessary).

What are your suggestions?
What do you do when using inheritance in your beans?

Any comments would be appreciated.

Randahl.


Reply via email to