使用你的AppDelegate作为你的Singleton是不好的做法吗? [英] Is it a bad practice to use your AppDelegate as your Singleton?
问题描述
我有时在我的项目中使用Singleton(存储几个不同类使用的数据),我想为什么不使用我的AppDeletage,因为它已经是一个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?
推荐答案
没有正确你会得到很多意见。我看到没有使用AppDelegate的问题,我做所有我的应用程序:
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:
- 委托是iPhone应用程序, / li>
- 它在应用程序的生命周期内;
- ,并且可以从程序的任何地方访问它(尽管不要滥用它!
但是必须保持警惕,所以不一定必须在那里的代码不存在。
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.
此问题已在StackOverflow上回答:
The question has been answered before on StackOverflow:
这些答案也可以帮助你。
The answers on that may help you also.
这篇关于使用你的AppDelegate作为你的Singleton是不好的做法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!