• 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: Best practices with singletons
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Best practices with singletons (From: William Squires <email@hidden>)

  • Prev by Date: Re: IKImageBrowserCell
  • Next by Date: Re: Other app blocks mine from opening my documents
  • Previous by thread: Re: Best practices with singletons
  • Next by thread: File's owner in nib file
  • Index(es):
    • Date
    • Thread