• 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: ARC and Singletons
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ARC and Singletons


  • Subject: Re: ARC and Singletons
  • From: Karl Goiser <email@hidden>
  • Date: Tue, 02 Aug 2011 16:22:13 +1000

Yes they are.


They are a kludge that came about because C++ doesn’t implement object behaviour properly.

Try this: http://www.google.com/search?hl=en&q=Singleton+evil


You have not said what about NSFileManager is a great example of the singleton pattern.


Of course class methods have their purposes: lots of them!
Normally, not even a class method is allowed to break encapsulation.  What I think you mean is that a class method sets class properties that all instances of that class refer to..


Of course, class methods aren’t a replacement for the singleton pattern: the singleton pattern is a fix for inadequately designed languages.


Karl



On 02/08/2011, at 2:02 PM, Kyle Sluder wrote:

> On Mon, Aug 1, 2011 at 7:14 PM, Karl Goiser <email@hidden> 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@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

  • Follow-Ups:
    • Re: ARC and Singletons
      • From: Jean-Daniel Dupas <email@hidden>
References: 
 >ARC and Singletons (From: Jeff Kelley <email@hidden>)
 >Re: ARC and Singletons (From: Dave Zarzycki <email@hidden>)
 >Re: ARC and Singletons (From: Kyle Sluder <email@hidden>)
 >Re: ARC and Singletons (From: David Duncan <email@hidden>)
 >Re: ARC and Singletons (From: Jeff Kelley <email@hidden>)
 >Re: ARC and Singletons (From: Karl Goiser <email@hidden>)
 >Re: ARC and Singletons (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: ARC and Singletons
  • Next by Date: Re: ARC and Singletons
  • Previous by thread: Re: ARC and Singletons
  • Next by thread: Re: ARC and Singletons
  • Index(es):
    • Date
    • Thread