| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Senior Member
Join Date: May 2006
Posts: 139
|
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? |
|
|
|
|
|
#2 |
|
as[org].addListener(this)
Join Date: Dec 2005
Location: LA, California
Posts: 838
|
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? |
|
|
|
|
|
|
|
|
#3 |
|
Pipty rupees only!
Join Date: Jul 2007
Location: Novosibirsk, Russia
Posts: 1,713
|
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 |
|
|
|
|
|
#4 |
|
Member
Join Date: Aug 2007
Location: Ascot, UK
Posts: 67
|
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 |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|