Re: Newbie Key Value-coding and Subclasses Question
Re: Newbie Key Value-coding and Subclasses Question
- Subject: Re: Newbie Key Value-coding and Subclasses Question
- From: Kieran Kelleher <email@hidden>
- Date: Fri, 10 Feb 2006 08:19:59 -0500
Note that one place where you might use instanceof frequently is in
WOComponent subcomponent design where the subcomponent is used for
edit/display of an EO from an inheritance hierarchy. For example you
may have a WOComponent that takes a "vehicle" binding. However your may
use a conditional that checks instanceof to show attributes relevant to
the subclass that has been bound to the vehicle binding. In this way
the "wingSpan" field only shows for vehicles that are instanceof
"plane" wherre plane is a subclass of vehicle. ERXInstanceofConditional
in Project Wonder does this conveniently by binding the object and the
subclass name.
Note that instanceof here is _NOT_ being used in business logic (which
is bad), but is being used in GUI display logic.
Regards, Kieran
On Feb 9, 2006, at 1:34 PM, Chuck Hill wrote:
Hi,
On Feb 9, 2006, at 9:59 AM, Arturo Perez wrote:
David Avendasora wrote:
I have a reputation as being a bit ummm *strict* in my interpretation
of what the proper O-O way is of doing things. It has served me well
with code and less so with ppl :-)
LOL
On question 1, I am currently testing for what type of Class it is
by reading my PartType field using:
if (((String)
valueForKeyPath("part.partType.partTypeName")).equals("Finished
Part")) {...}
and this works just fine, but my understanding was that instanceof
is a better OO way of doing things - especially since the string
partTypeName is a value from a DB field which could potentially
change.
The problem isn't so much with doing the above or using instanceof.
The problem is that once your code becomes aware of object-types then
you're on a slow sure path to perdition. You might want to take a
look at the book HeadsFirst Design Patterns (the typical GoF
reference is too heavyweight for most developers) for reasons to
avoid instanceof et al.
Just another voice from the wilderness here echoing that you want to
think long and hard before using instanceof or anything similar. It
does creep into my code from time to time, but only (well, usually) as
an expedient hack around a prior design flaw.
Chuck
--
Coming in 2006 - an introduction to web applications using WebObjects
and Xcode http://www.global-village.net/wointro
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:
email@hidden
This email sent to email@hidden
_______________________________________________
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