|
|
||||
MyMVC, Adobe AIR (Flex) application framework |
||||
|
|
||||
DownloadMyMVC source and binary | Documentation | Example PrinciplesMyMVC is a framework for Adobe AIR (or Flex) applications. It is designed with the following principles (in addition to standard model-view-controller principles):
Commands are like bricks and front controller, to build a complex building, should be able to combine them differently in different situations. This also makes individual commands reusable. MyMVC allows you to combine commands in a straightforward way. Below is some sample codes of controller in MyMVC:
The first line is what you usually see in a regular MVC framework (e.g. Cairngorm) where a single command is registered against a single event. If you want to perform command A, then B, then C for event 'E', you will have to write a new command, say X, to perform A-B-C. In MyMVC, however, you simply write something like line 2 or 3. This way, each individual command class is highly reusable and they can be combined in whatever way you want without writing new command classes. Commands should dispatch events Linux commands are straightforward. They receive some input and then (maybe after a long time) spit out the result (output). This simplicity makes it not only useful, but also highly reusable. Commands in any MVC framework should do the same thing: input then output. In MyMVC, command classes spit out output in the term of events (MyMVCEvent). If they perform their jobs successfully, they dispatch "complete" event which also includes the result. If fails, they dispatch "error" event which also includes the error message. If the process is lengthy, they may dispatch "progress" event with progress information. The ability of dispatching events also makes sequence command mentioned above possible. How does the front controller know when the first command finishes and then call the second command? Event. Front controller can do "switching" workFront controller is like a manager who assigns jobs (events) to workers (commands). In a real-life application, it's frequent that the controller needs to assign jobs depending on result of previous commands. In MyMVC it's easy to to write such switching codes:
Event has "who" and "what" properties When an event is broadcasted, it's natural to inquire who broadcasts the event, and what function broadcasts the event in addition to the content of event. This is especially useful in MVC framework as many events are usually broadcasted (i.e. dispatched by a central agent), instead of dispatched. Let's say the front controller heard 'complete' event, he should know who completes the job and then can decide what to do next. Example
Relation with CairngormMyMVC was adopted from Cairngorm. It also incoporates many good features from real life applications (such as Employee Directory). The principles listed above makes it flexible and easy to build complex applications. MyMVC based applicationsRelated |
||||
|
|
||||
|
Xu Cui (cuixiaofei AT gmail.com)
3/20/2009 |