Reputation: 117
In iOS, AppDelegate is the singleton class then why I need a separate singleton class to handle global variables? Why not use AppDelegate as a global singleton? Any specific reason behind this.
Upvotes: 0
Views: 33
Reputation: 594
The main reason probably comes down to Separation of Concern. For example, if you have the same data that needs to be displayed across the application, you might choose to make a Singleton class called DataManager that deals with retrieving, saving, editing and deleting this data. Yes, you can add all the same functionality through the App Delegate and as a result it might be the same, but if having organized and readable code is a concern for the developer (and definitely is a concern if you develop for a company, or expect someone else to possibly continue on with your code), then if you made a DataManager singleton whoever is working on the code can clearly understand what the responsibilities of this class are based on it's name.
Making separate classes also helps you reduce having huge classes that become hard to understand. If you had a DataManager, APIManager, and another manager in your app, then putting all of that functionality into one AppDelegate can become confusing as your app grows.
Upvotes: 1