Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a bad practice to use your AppDelegate as your Singleton?

I'm sometimes using a Singleton (to store data that is used by several different classes) in my projects and I'm thinking why not use my AppDeletage, since it's already a Singleton and easy to access. Is this a bad practice and if so, why?

like image 304
Man of One Way Avatar asked Jul 15 '11 14:07

Man of One Way


1 Answers

There is no right answer to this one. You'll get many opinions on this. I see no issue with using the AppDelegate, and I do it for all my apps:

  • The delegate is practically mandatory for iPhone apps,
  • it's there for the lifetime of the app;
  • and one can access it from anywhere in the program (although don't abuse that!).

One must remain vigilant though, so that code that doesn't necessarily have to be there, isn't there. You don't want your AppDelegate to become massive and unmaintainable.

The question has been answered before on StackOverflow:

Application Design and AppDelegate

The answers on that may help you also.

like image 161
ageektrapped Avatar answered Oct 22 '22 10:10

ageektrapped