cocoa - Singleton & Notification -


i have been developing cocoa apps while , have conceptual question regarding singleton "pattern" , use of nsnotificationcenter communication.

suppose have class responsible storing credentials of user in app. lets call useraccountcontroller. such class exposes public methods perform login/logout operations , notify any interested object such operations performed (e.g.: in tab bar application, i'd update uiviiewcontrollers when user logged out).

in opinion, wouldn't make sense have more 1 useraccountcontroller object in application, also, second useraccountcontroller object post notifications nsnotificationcenter, may cause troubles objects registered receive such notifications.

given situation have 2 questions:

  1. what pattern use in classes useraccountcontroller.
  2. any class uses nsnotifications information flow in application should, necessarily, implement singleton "pattern"?

by analyzing apple's classes have found question 2) makes sense, avoid singleton "pattern".

any clues?

i store user credentials in useraccountmodel object. object hold among other things current state, i.e. login status. whenever status changes, post notification fact. uiapplicationdelegate hold reference model. now, let's have view user enters login credentials, loginview. mvc useraccountmodel -> loginviewcontroller -> loginview.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -