The Model-View-Controller Design Pattern in Actionscript 3

The-Model-View-Controller
http://en.wikipedia.org/wiki/Model_view_controller

The MVC Design Pattern

  • Creates a separation of Class roles
  • Adds a clear and logical communication structure
  • Increases flexibility in larger applications

Model
Handles data storage and retrieval (eg. Store character x position)
View
Handles the display/communication (eg. Position character on stage)
Controller
Handles most the of the application logic (eg. Get current x position)

MVC – basic structure
Each model can have multiple views
Each view has at least one matching controller
Creates a separation between form, content and action
The model becomes the base of the application

Communication Model

Overview of the MVC design pattern
MVC planning example - Pacman Game

Here is a simple application to show MVC in action

Application abstract:
A circle which changes colour randomly every time a button is pressed

Designing the simple application
Overview of basic MVC example

Broken down into the MVC pattern this would look like:

Overview of basic MVC example

Overview of basic MVC example

Download a basic Actionscript 3 MVC example that shows how to move an object around the stage using the keyboard.

Download a basic Actionscript 3 MVC example that shows how to load and display text stored in an external text file.

Download the MVC circle example discussed in the tutorial.

For more on the Model View Controller and other Design Patterns in Actionscript 3 check out 'Actionscript 3 Design Patterns' by William Sanders and Chandima Cumaranatunge.

Nhận xét

Đăng nhận xét

Bài đăng phổ biến từ blog này

Ký tự viết tắt trong chat & email

dung lượng RAM lớn nhất mà HĐH cấu trúc 32-bit nhận được

Ubuntu LAMP Server