Note that there are some explanatory texts on larger screens.

plurals
  1. POWhich design is a better? A singleton object or pass an object everytime?
    text
    copied!<p>I have a view, controller and model. which is a desktop application, let say it is a browser. So, there have an object called AppCurrentStatus. Which contain the windows position, how many window is opening, and the window content. </p> <p>So, let say, user wanna to open a new tab, and the flow is work like this:</p> <pre><code>1. View (user interface) press new a tab. 2. Fire event to controller. 3. Controller update the AppCurrentStatus, add one new tab. 4. Controller notify the model, the model store the data, just in case the user close the browser incidentally </code></pre> <p>The question is, how the view, controller and model get the information they need from AppCurrentStatus? Should I make the AppCurrentStatus become a singleton, that allow everyone can call it. For example, the user can have more than 3 tabs, and the controller can call it directly via a singleton, to check whether it have 3 tabs or not. If new tab is successfully added, will can the model save the AppCurrentStatus with in asking the controller, just call it from singleton. </p> <p>Another approach is keeping the AppCurrentStatus as a variable in the controller, when user add a new tab, the event will fire and tell the controller check it self's AppCurrentStatus, if it is modify, just pass this object to model, to save it. </p> <p>More specify to tell the different, the model will like this, approach one:</p> <pre><code>-(void)save(); //calling singleton </code></pre> <p>if approach two is something like this </p> <pre><code>-(void)save(AppCurrentStatus aAppCurrentStatus); //save from a object </code></pre> <p>or other better solutions can be suggested?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload