Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > General > Best Practices

Reply
 
Thread Tools Rate Thread Display Modes
Old 12-09-2008, 07:17 PM   #1
Groady
Senior Member
 
Join Date: May 2006
Posts: 139
Default MVC and handling states

I'm still trying to get my head around MVC specificially on where certain code should go.

My question is on handling state. I'm referring to a state machine (state design pattern). Should a state machine generally be part of a controller or part of the model?

Use a drawing application like photoshop for example. When you mouse down on the canvas an action occurs which is specifc to the current tool selected. The brush tool leaves a mark on the canvas, and the magnify tool zooms the canvas.

I first thought "well the zoom doesn't need to effect the model because it's only the view that needs to change". But now I realise there could be other views that need to be updated like a text output showing the zoom percentage or some kind of zoom slider ui.

The way I see it, the controller would receive 'TOOL_CHANGED' notifications from the model and then switch states so when mouseDown() is called on the controller it will invoke the correct method on the model like doBrush() or doZoom() in the case of the brush or zoom tools.

What do you think? Does that sound right? Does the control handle state changes in the way I've described?
Groady is offline   Reply With Quote
Old 12-09-2008, 09:42 PM   #2
Assertnfailure
as[org].addListener(this)
 
Assertnfailure's Avatar
 
Join Date: Dec 2005
Location: LA, California
Posts: 838
Default

The state pattern isn't meant to solve specific architectural challenges, but rather more specifically, any situation where behavior changes based the state of an object. State machines can be used for views as well as controllers, depending on what you're trying to accomplish.

State machines are typically confined to just the class that uses them, so they really bear no weight on an architecture as a whole.

In this case the only concern for the MVC system is that user gestures are being picked up by the controller, and the controller decides how those gestures affect the canvas. Therefore you'd probably have a state machine managed internally by the controller for different tools.

Does that make sense?
Assertnfailure is offline   Reply With Quote
Old 12-12-2008, 05:52 AM   #3
rawmantick
Pipty rupees only!
 
rawmantick's Avatar
 
Join Date: Jul 2007
Location: Novosibirsk, Russia
Posts: 1,713
Default

There is a new Finite State Machine utility for PureMVC, probably you'll find it usefull

http://trac.puremvc.org/Utility_AS3_StateMachine
__________________
fly high
rawmantick is offline   Reply With Quote
Old 12-13-2008, 08:00 PM   #4
NickZA
Member
 
NickZA's Avatar
 
Join Date: Aug 2007
Location: Ascot, UK
Posts: 67
Default

Groady,

While I would imagine they can be used for the View(s), I think you'll find states are nearly always used in the controller (the "true" logic) of your MVC application.

Fight the good fight! Onward to MVC Zen!
__________________
www.visualharmonics.co.uk
NickZA is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:00 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.