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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com