Re: ARC and Singletons
Re: ARC and Singletons
- Subject: Re: ARC and Singletons
- From: Jean-Daniel Dupas <email@hidden>
- Date: Tue, 02 Aug 2011 09:51:58 +0200
Le 2 août 2011 à 08:22, Karl Goiser a écrit :
> 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.
Since 10.5, you can create other instances of NSFileManager.
Thanks to the design it chooses (singleton pattern) it was possible to change its behavior without breaking the whole API.
> 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.
>
That's not because there is 2 way to do the same thing that one is The One True Way™ and the other is a poor practice used by bad programmers.
>
> 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
-- Jean-Daniel
_______________________________________________
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