Groady
12-09-2008, 07:17 PM
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?
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?