• 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: isKindofClass with NSData and NSKeyUnarchiver
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: isKindofClass with NSData and NSKeyUnarchiver


  • Subject: Re: isKindofClass with NSData and NSKeyUnarchiver
  • From: Uli Kusterer <email@hidden>
  • Date: Fri, 28 May 2010 18:19:13 +0200

On May 28, 2010, at 4:00 PM, Sherm Pendley wrote:
> I would let the sent objects handle the work themselves. A switch or
> series of ifs based on class is an OOP anti-pattern. Polymorphism is
> often a better alternative, and Objective-C's ability to add a
> category to any class makes it easy to implement. So,  I would extend
> NSString, UIImage, etc. - whatever types can be sent - by adding a new
> method "mySuperDuperMethod" (for example).
>
> Then, what you're left with in the receiver class is simply:
>
>    if ([obj respondsToSelector(@selector(mySuperDuperMethod))]) {
>        [obj performSelector:@selector(mySuperDuperMethod)];
>    }
>
> If the ability of a sent object to implement mySuperDuperMethod is
> critical, you could add an else block to log and/or assert any such
> failures.

 This isn't a good choice in many cases, though. It leads people to tack a lot of unrelated functionality onto foundational classes. You'd end up with "everything is a dictionary" if you followed through on that.

-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >isKindofClass with NSData and NSKeyUnarchiver (From: Philip Vallone <email@hidden>)
 >Re: isKindofClass with NSData and NSKeyUnarchiver (From: Ken Thomases <email@hidden>)
 >Re: isKindofClass with NSData and NSKeyUnarchiver (From: Graham Cox <email@hidden>)
 >Re: isKindofClass with NSData and NSKeyUnarchiver (From: Philip Vallone <email@hidden>)
 >Re: isKindofClass with NSData and NSKeyUnarchiver (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Re: six things I wasn't able to do with Cocoa
  • Next by Date: Re: six things I wasn't able to do with Cocoa
  • Previous by thread: Re: isKindofClass with NSData and NSKeyUnarchiver
  • Next by thread: Problem getting correct file URL in NSTask process
  • Index(es):
    • Date
    • Thread