Re: Of Inheritance and AwakeFromInsertion
Re: Of Inheritance and AwakeFromInsertion
- Subject: Re: Of Inheritance and AwakeFromInsertion
- From: Chuck Hill <email@hidden>
- Date: Wed, 19 Mar 2008 08:02:58 -0700
On Mar 19, 2008, at 5:21 AM, David Avendasora wrote:
Hi all,
I've run into something that _seems_ to work, but just seems "wrong"
and I don't see how to do it "right".
I have the following inheritance structure in my model:
LotCode (NOT abstract)
ManufacturedBatch extends LotCode.
When I call awakeFromInsertion on the superclass I do it as follows :
public void awakeFromInsertion(EOEditingContext ec) {
super.awakeFromInsertion(ec);
if (lotCodeType() == null) {
setLotCodeType(1);
}
}
But when I call awakeFromInsertion on the subclass I have to do this:
public void awakeFromInsertion(EOEditingContext ec) {
super.awakeFromInsertion(ec);
if (lotCodeType() == null || lotCodeType.equals(1)) {
setLotCodeType(2);
}
}
I know that you should _never_ change the class of an EO after
creating it, but that's exactly what I'm doing here.
Well, no. You are changing the value that EOF uses to determine class
when it fetches the object.
When awakeFromInsertion is called on the subclass, the first thing
it does is call super.awakeFromInsertion, which sets the class to
LotCode, but then I change it to a ManufacturedBatch immediately
after.
The Java object is already created. It class does not and can not
change.
If I don't do this, a call of ManufacturedBatch newManufacturedBatch
= new ManufacturedBatch() returns a LotCode instead.
! (newManufacturedBatch instanceof ManufacturedBatch)? That seems
highly improbable just after a call to new.
So, is this an exception to the rule "never change an EO's class" or
is it because I'm doing it in the awakeFromInsertion process that it
is okay?
Or is it wrong to do this and I just haven't been bitten by it yet?
Either your description above is inaccurate, or something is totally
wacked out in your code.
Chuck
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden