Re: isKindofClass with NSData and NSKeyUnarchiver
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