Recently, there's been a lot of chatter regarding the Mate framework, so last night started a little project to try it out.
This slightly useless little application allows users to create any number of coloured boxes (which I refer to as GraphicLayers), either filled or unfilled. They can select any of the GraphicLayers using a list view on the left and edit them. Let me run through the architecture to give you some insight into developing using Mate.
The fundamental object is a GraphicLayer - this is a value object that defines how our boxes will be rendered. Also inside my models directory is the GraphicLayersManager which contains an array collection of GraphicLayers and the business logic surrounding it.
I've created four view classes:
- An Editor class that allows users to edit the properties of the currently selected GraphicLayer
- A Renderer class that renders a GraphicLayer
- A Thumbnail class that extends the Renderer but at a thumbnail size
- A ListView class that lists the array collection of GraphicLayers and uses the Thumbnail class as its item renderer. The list view allows the user to define the currently selected GraphicLayer which is displayed in the Renderer and is editable in the Editor.
The view classes dispatch different events depending on user activity:
- The GraphicLayerChangeEvent is dispatched when a user edits or adds a GraphicLayer. The event has two types - a change and an add.
- The GraphicLayerSelectionChangeEvent is dispatched when a user changes the current selection in the list view.
Under the maps directory is the MainEventMap class. This class glues everything together using either EventHandlers or Injectors.
- EventHandlers have a type property which refers to the event type. When a view dispatches an event, it is these that invoke methods on the GraphicLayersManager to change the array collection of GraphicLayers.
- Injectors define the binding between properties of the GraphicLayersManager and view objects.
Having all the plumbing in a central location makes navigating the architecture of your application really easy. However, I do have reservations about the lack of checking at compile time of some of the properties in classes like the MethodInvoker's method property. Luckily, the Mate debugger is really helpful and using Flex's debug feature helps locate bugs and niggles very quickly.
Overall, I really like Mate - it feels a lot lighter than Cairngorm and was a breeze to pick up. I've enabled the source code view on this little application, I hope it helps towards your understanding of this new framework.
The application is available here.
simon gladman


5 comments:
Thanks you for your example. I heard and saw a lot about this framework from my colleagues, but I have hadn't time to try. Of course cairgorm is a great framework but for small application it requires quite a lot of redundant coding.
Thanks for this example Simon. It really helps me understand the framework. But one question... You said:
'When a view dispatches an event, it is these that invoke methods on the GraphicLayersManager to change the array collection of GraphicLayers.'
Are the method of a particular instance of the GraphicLayersManager being invoked? If so, where is the GraphicLayersManager object being instantiated? How are you referencing it?
Sorry if these are senseless questions, I'm just trying to get my head around how it all plugs together.
BTW - as a person who thinks in graphical terms I would love to see a diagram of all the objects and how they interact. Do you happen to have such a thing?
thanks
"...where is the GraphicLayersManager object being instantiated?"
The event map creates the object with the createInstance() method.
I'm currently porting my CFD application to Mate - that's a lot more challenging, but I'll document the event map stuff a bit better :)
Thanks for your comments,
Simon
Thanks Simon,
I had the same question as saffell.
"The event map creates the object with the createInstance() method."
I'm not seeing this in the source. Is it the case that the injectors are wired up as soon as the app is instantiated. The closest thing I could find was on the event map:
Injectors target="{ListView}"
PropertyInjector targetKey="graphicLayersArrayCollection" source="{GraphicLayersManager}" sourceKey="graphicLayersArrayCollection"
I like Mate cause none of the framework code is in your model, the presenter, or the view. Just the map that interprets the events and fires off the model and presenter.
Post a Comment