I'd expect the instanceof check will be much more efficient than catching an exception. From an OO design point of view, I'd add a billsOfMaterial() method to the Part class that simply returns NSArray.emptyArray. ManufacturedPart will then override this to return the correct result for a ManufacturedPart.

Chuck



On Apr 7, 2008, at 6:34 AM, Bob Stuart wrote:

Try catch seems expensive to me. Why not just check with
if  (aPart instanceof ManufacturedPart){
        do something with aPart.billsOfMaterial()
}

At 9:12 AM -0400 4/7/08, David Avendasora wrote:
Hi all,

This is more of a Java question than a WO-specific one

I have an Inheritance structure in my app:

Part (abstract Superclass)
RawMaterial (subclass of Part)
ManufacturedPart (subclass of Part)

I have an NSArray of Parts that could be, RawMaterial instances, ManufacturedPart instances, or most likely, a mixture of the two.

I want to iterate through the Array and get the contents of the Part.billsOfMaterial() (toMany) relationship. The problem is that while ManufacturedParts have this relationship, RawMaterials do not.

Right now, I'm using a try-catch block that catches the exception on RawMaterial.billsOfMaterial() and just ignores it.

I could also add a billsOfMaterial() method to the RawMaterial class that simply returns NSArray.emptyArray.

Is one way better than the other for any reason?

Thanks,

Dave
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/bobstuart%40mcf.com

This email sent to [EMAIL PROTECTED]


--
Bob Stuart
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/chill%40global-village.net

This email sent to [EMAIL PROTECTED]


--

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      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to