On Apr 17, 2011, at 11:52 AM, Joanna Carter wrote:
> Tell me; maybe it's my background in other languages, but I would tend to use 
> a "static class" as a singleton; or, at least, design a class with only class 
> methods/properties, with static "fields" declared in the @implementation 
> section of a class.
> 
> Why this fascination with going to all the trouble of creating a singleton 
> rather than using the "static class" approach?

A narrow technical reason: Objective-C's type system is limited when it comes 
to class objects. Singleton instances are better supported.

A software lifecycle reason: Sometimes an app evolves such that a task that 
used to be performed globally now needs to have multiple different local 
contexts. (Perhaps you wrote a single-window app with a singleton window 
controller, and now you want a multiple-window app.) Code written for a 
singleton instance can often be transformed to work with multiple instances. 
Code written for a static class may need more rewriting to handle the change.


-- 
Greg Parker     gpar...@apple.com     Runtime Wrangler


_______________________________________________

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

Reply via email to