I want to re-factorise some of my code (edoboard.com) as i am starting to feel the need for a better architecture and i realised i was doing many things badly even within the boundaries PureMVC (mixing mediator and proxy roles, not enough commands and so on.
Here is a simplified diagram of the current classes.http://i34.tinypic.com/24fxuft.png
On the view side i have Tabs, each Tab holding a Canvas where i can draw and manipulate shapes.
Therefore we have a BoardManagerMediator
handling the following actions: close tab, add tab, duplicate tab. It also keeps reference to a proxy called BoardManagerProxy
keeps a list of BoardMediators (one boardMediator = one tab).
It also have attributes like 'currentBoardMediator' 'currentShape' 'selectedShapes' ...
1.Is it the good place to hold these ?
2.What about the naming, does it make sense ?Shapes
When i add a shape the BoardMediator
i s responsible for listening to the mouse down / move / up events. It looks in a toolbarProxy
to see the current selected shape and starts drawing it on mouse down.
That is just the instantiation of a Circle Shape and resizing its width/height on mouse move until a mouse up.
On mouse up the boardMediator
pushes the shape to Shape list boardProxy
, and send a Notification (with the new shape as the body) to the BoardManagerMediator
update the current Shape attribute on its boardManagerProxy
. The shapeid counter (boardManagerProxy) is also incremented.
3. I definitely forgot a lot of things but is there any big architecture flaws so far ?Each Shape needs a mediator and a Model (proxy) ?.
Sample of a simpleShapeModel
public class SimpleDataModel implements IResizeable, IMoveable
[Bindable] public var x:Number = 10;
[Bindable] public var y:Number = 10;
[Bindable] public var height:Number = 50;
[Bindable] public var width:Number = 50;
[Bindable] public var rotation:Number = 0;
Should the proxy hold the model ? Or should the model be also a proxy ?
Actually i need a minimalist mediator since all rotation/move stuff are handled by an external library (objecthandle).
My mediator will just keep a reference to the model and offers functions like update fill color, opacity etc. These functions will be called by the boardMediator
. we do not want all shapes to listen for the update color notification and check if its for them.
So at the end my boardProxy
will hold a list of ShapeMediator
I want to redo my multi selection to handle ctrl key to remove a shape from a selection and shift to add one. I was going to do it from the shape mediator.
The shape know when it receives a mouse down event with ctrl/shift key activated. That means all shapes listen for ctrl/shift key ?
It then fires an event like 'add_to_selection_group' which is catch by the boardMediator
. The boardMediator
send a addShapeToGroupCommand
Maybe it is at the boardMediatorManager
level that we should look for the ctrl/shift key ?
Anyway our addShapeToGroupCommand
will get a hand on the currentBoardMediator from boardManagerProxy
and manipulate it to redraw the selection area, and update the boardManagerMediator
proxy selectedShapes attribute.
That is way too long and maybe not very intelligible, but i have no occasion to share these design questions
Looking to have some good design i can be happy to look at.