On Mon, Aug 1, 2011 at 7:14 PM, Karl Goiser <[email protected]> wrote:
> Wow, class methods finally get the tick of approval!  Only 30+ years after 
> being specified in the Smalltalk standard..
>
>
> Forget about singletons: they are just a workaround for not having class 
> methods/variables.

No, they're not. I mentioned the NSFileManager example above; that was
a great example of how the singleton pattern is more flexible than
using class methods for the same task.

Class methods have their purpose. Cocoa and Cocoa Touch use them to
great effect in places like +[UIView setAnimationsEnabled:], where the
method logically applies to instances of that class. They help
maintain encapsulation, since they are defined inside the class and
therefore, following typical good design principles, are allowed to
peek behind the public veil of instances.

But class methods aren't a replacement for the singleton pattern. Even
if we had class storage (which in practice would be no different from
static global variables except for scope), class methods would still
be appropriate for a different set of tasks.

I wouldn't hold my breath waiting for Apple or anyone else to drop the
singleton pattern and adopt class methods.

--Kyle Sluder
_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to