Re: Best practices with singletons
Re: Best practices with singletons
- Subject: Re: Best practices with singletons
- From: Dave <email@hidden>
- Date: Tue, 10 Jun 2014 16:28:55 +0100
Hi,
You should take a look at this article:
http://c2.com/cgi/wiki?SingletonsAreEvil
Cheers
Dave
On 8 Jun 2014, at 17:30, William Squires <email@hidden> wrote:
> Okay, I have several classes in my (somewhat large, and growing) project that implement the singleton pattern via a [<classname> shared<whatever>] class method (and a file-scope static reference) that uses lazy loading to instantiate the singleton the first time a reference is asked for. Is it considered better to put all of these calls in the main() function before any other code executes, or not worry about it, and just access them through the above class methods when and where needed?
> Also, in C, it's common to throw away the return value from a function (a la printf(), which returns an int, but coders rarely use the return value), but is it good practice to throw away the result of the above method calls (messages) just to silence the compiler?
>
> i.e.
>
> -(void)someMethod
> {
> ...
> [MyClass sharedController]; // No warning here.
> ...
> }
>
> as opposed to:
>
> -(void)someMethod
> {
> MyClass *p = [MyClass sharedController]; // <- Yellow triangle here for unused variable 'p'
> ...
> }
>
> TIA! :)
>
>
> _______________________________________________
>
> 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
_______________________________________________
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