I have been developing Cocoa Apps for a while and I have a conceptual question regarding the Singleton "pattern" and the use of the NSNotificationCenter
for communication.
Suppose I have a class that is responsible for storing the credentials of the user in the app. Lets call it UserAccountController
. Such class exposes public methods to perform login/logout operations and notify any interested object that such operations were performed (e.g.: in a tab bar application, I'd like to update all UIViiewControllers when the user logged out).
In my opinion, it wouldn't make sense to have more than one UserAccountController
object in the application, also, a second UserAccountController
object could also post notifications to the NSNotificationCenter
, which may cause troubles to objects registered to receive such notifications.
Given this situation I have two questions:
- What pattern to use in classes like
UserAccountController
. - Any class that uses NSNotifications for information flow in the application should, necessarily, implement the Singleton "pattern"?
By analyzing the Apple's classes I have found that the question 2) makes sense, but I would like to avoid the Singleton "pattern".
Any clues?