(Go to ‘Cairngorm Series‘ to view all titles)
This is the first post in a new series on Cairngorm fundamentals. I begin the series with three steps towards a Model View Controller implementation using familiar concepts and no framework. Future posts will build on these concepts using the Cairngorm framework until we have built a working application.
Moving towards MVC without Cairngorm
Get the Flash Player to see this player.
(Right click to view source)
MVC: Where are we headed?
Cairngorm is a Model View Controller framework for Adobe Flex. That means the applications we build with Cairngorm will have three distinct parts: one Model, at least one View, and one Controller.
Model: One place to store data that is accessible to the whole application.
View: Binds to data in the Model and dispatches events when a user interacts with the application (example: clicking a button).
Controller: One place to listen for those events and handle them. The event handler may modify data in the Model which, consequently, updates Views that are bound to the updated data.
Moving from the example above towards a Cairngorm application
This example demonstrates the basic flow of an MVC application. It is important to understand this flow and the goals it intends to achieve.
- The View binds to application data in the Model
- The Model gives us one and only one place to store data. It also makes that data accessible to any View in the entire application through binding. This means that an application could have multiple views that display the same data.
- A user ‘does something’ which causes the View to dispatch an event
- Views are intentionally simple. They will never modify data in the Model directly - the only way they get things done is by dispatching events.
- The Controller listens for the event and executes some code, typically updating the Model
- It is the Controller’s job to listen for those events and then execute some code when the event is heard. This allows us to break the functionality of the application into small chunks of code making it easier to maintain the application and add features.
- The View is automatically updated through data binding when the Model is modified.
The following chapters will take you through this process step by step. I won’t just give directions; we will walk through the Cairngorm framework code to understand how it works. It’s really quite simple and I think you’ll enjoy it.
(Go to ‘Cairngorm Series‘ to view all titles)
Scot,
Thanks again for the great videos. I am in the middle of trying to use MVC inside all my future projects. This is really a valuable tool in developing Flex applications that are scalable and the sooner myself and other developers implement this type of architecture the better.