Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

should a singleton use self or shared instance inside the methods

inside the singleton methods how should I use a singleton:

like:

     [self doMethod];

or:

    [[SingletonClass sharedSingleton] doMethod];

?

like image 278
Flores Robles Avatar asked Dec 21 '25 09:12

Flores Robles


1 Answers

I can think of no reason to do it the second way. That way is longer, slower and more brittle -- and there's no upside to it. Just use self unless you have a really compelling reason to do otherwise. Singletons are essentially just normal objects.

like image 62
Chuck Avatar answered Dec 23 '25 01:12

Chuck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!