• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Best Way® to test for existence of a rela tionsh ip
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best Way® to test for existence of a rela tionsh ip


  • Subject: Re: Best Way® to test for existence of a rela tionsh ip
  • From: Chuck Hill <email@hidden>
  • Date: Mon, 7 Apr 2008 08:28:31 -0700


On Apr 7, 2008, at 8:26 AM, Bob Stuart wrote:

At 11:20 AM -0400 4/7/08, David Avendasora wrote:
On Apr 7, 2008, at 10:36 AM, Mike Schrag wrote:

I'd expect the instanceof check will be much more efficient than catching an exception.
By far ...

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.
Ew gross ...

By far one of my favorite technical arguments.

If it's not an attribute of all Parts, then from an OO design standpoint it shouldn't be on Part. I agree if your argument is based on "the convenience of being able to call billsOfMaterial on the entire array," though.

Yeah, I'm getting the impression that there's no really "ungross" OO way to do this. I think this and instanceOf are equally "gross" because if I add other classes that have a billsOfMaterial() relationship, then I'd have to remember to come here and add it to the list of things instanceOf checks.


I think I'll go with adding the billsOfMaterial() method to Part because then I can use this same logic in more places without having to write the instanceOf check every time.

If you want to avoid adding the method to Part you could create an interface and have the instance of check that. Then only the classes that have this would implement the interface. That way you only have to change things when you make the new class and only in the class not however many places you might do the instanceof check.


Using instanceof on a member of an inheritance hierarchy is a bad code smell. It is the code's ways of telling you that your design is wrong. IMO.


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


  • Follow-Ups:
    • Re: Best Way® to test for existence of a rela tionsh ip
      • From: Mike Schrag <email@hidden>
    • Re: Best Way® to test for existence of a rela tionsh ip
      • From: Ken Anderson <email@hidden>
References: 
 >Best Way® to test for existence of a relationship (From: David Avendasora <email@hidden>)
 >Re: Best Way® to test for existence of a relationsh ip (From: Bob Stuart <email@hidden>)
 >Re: Best Way® to test for existence of a relationsh ip (From: Chuck Hill <email@hidden>)
 >Re: Best Way® to test for existence of a relationsh ip (From: Mike Schrag <email@hidden>)
 >Re: Best Way® to test for existence of a relationsh ip (From: David Avendasora <email@hidden>)
 >Re: Best Way® to test for existence of a rela tionsh ip (From: Bob Stuart <email@hidden>)

  • Prev by Date: Re: Best Way® to test for existence of a relationsh ip
  • Next by Date: [Meeting] Chicago CocoaHeads / Cawug - MacRuby
  • Previous by thread: Re: Best Way® to test for existence of a rela tionsh ip
  • Next by thread: Re: Best Way® to test for existence of a rela tionsh ip
  • Index(es):
    • Date
    • Thread