Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I got a prezi-presentation about a pattern that I call "State First".</p> <p>It is a combination of MPV/IoC/FSM and I've used it successfully in .Net/WinForms, .Net/Silverlight and Flex (at the moment).</p> <p>You start by coding your FSM:</p> <pre><code>class FSM IViewFactory ViewFactory; IModelFactory ModelFactory; Container Container; // e.g. a StackPanel in SL ctor((viewFactory,modelFactory,container) { ...assignments... start(); } start() { var view = ViewFactory.Start(); var model = ModelFactory.Start(); view.Context = model; view.Login += (s,e) =&gt; { var loginResult = model.TryLogin(); // vm contains username/password now if(loginResult.Error) { // show error? } else { loggedIn(loginResult.UserModel); // jump to loggedIn-state } }; show(view); } loggedIn(UserModel model) { var view = ViewFactory.LoggedIn(); view.Context = model; view.Logout += (s,e) =&gt; { start(); // jump to start }; show(view); } </code></pre> <p>Next up you create your IViewFactory and IModelFactory (your FSM makes it easy to see what you need)</p> <pre><code>public interface IViewFactory { IStartView Start(); ILoggedInView LoggedIn(); } public interface IModelFactory { IStartModel Start(); } </code></pre> <p>Now all you need to do is implement <code>IViewFactory</code>, <code>IModelFactory</code>, <code>IStartView</code>, <code>ILoggedInView</code> and the models. The advantage here is that you can see all transitions in the FSM, you get über-low coupling between the views/models, high testability and (if your language permits) a great deal of type safely.</p> <p>One important point in using the FSM is that your shouldn't just jump between the states - you should also carry all stateful data with you in the jump (as arguments, see <code>loggedIn</code> above). This will help you avoid global states that usually litter gui-code.</p> <p>You can watch the presentation at <a href="http://prezi.com/bqcr5nhcdhqu/" rel="nofollow noreferrer">http://prezi.com/bqcr5nhcdhqu/</a> but it contains no code examples at the moment.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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