Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / ActionScript Technology Center /

ActionScript 3 Design Patterns excerpt: Factory method and MVC

by William B. Sanders

William B. Sanders
  • sandlight.com

by Chadima Cumaranatunge

Created

10 September 2007

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
ActionScript Flash Builder Flash Professional MVC OOP

Requirements

User level

Intermediate

Now that ActionScript is reengineered from top to bottom as a true object-oriented programming (OOP) language, reusable design patterns are an ideal way to solve common problems in Flash and Flex applications. If you're an experienced Flash or Flex developer ready to tackle sophisticated programming techniques with ActionScript 3, this hands-on introduction to design patterns takes you step by step through the process. William B. Sanders and Chadima Cumaranatunge show you various types of design patterns and construct small abstract examples before trying your hand at building full-fledged working applications outlined in the book.

Topics in ActionScript 3 Design Patterns include:

  • Key features of ActionScript 3 and why it became an OOP language
  • OOP characteristics, such as classes, abstraction, inheritance, and polymorphism
  • Benefits of using design patterns
  • Creational patterns, including Factory and Singleton patterns
  • Structural patterns, including Decorator, Adapter, and Composite patterns
  • Behavioral patterns, including Command, Observer, Strategy, and State patterns
  • Multiple design patterns, including Model-View-Controller and Symmetric Proxy designs

During the course of the book, you'll work with examples of increasing complexity, such as an e-business application with service options that users can select, an interface for selecting a class of products and individual products in each class, an action game application, a video record and playback application, and many more.

The printed book is available through most major online and retail bookstores worldwide. For more information visit the O'Reilly store.

ActionScript 3 Design Patterns © 2007 William B. Sanders and Chandima Cumaranatunge. Reproduced by permission of O'Reilly Media Inc. All rights reserved.

Factory method pattern

One of the most common statements in object-oriented programming (OOP) uses the new keyword to instantiate objects from concrete classes. ActionScript applications that have multiple classes can have an abundance of code that looks like the following:

public class Client { public function doSomething( ) { var object:Object = new Product( ); object.manipulate( ); } }

The Client class creates a new instance of the Product class and assigns it to the variable object. There's nothing wrong with this code, but it does create a coupling or dependency between the Client and Product classes. Simply put, the Client class depends on the Product class to function properly. Any changes to the Product class in terms of class name changes or change in the number of parameters passed to it will require changes in the Client class as well. This situation is exacerbated if multiple clients use the Product class, and requires changing code in multiple locations.

The solution to this common problem is to loosen the tight coupling between the client and the concrete classes it uses. This is where the factory method pattern offers a robust solution. It introduces an intermediary between the client and the concrete class. The intermediary is called a creator class. It allows the client to access objects without specifying the exact class of object that will be created. This is accomplished by delegating object creation to a separate method in the creator called a factory. The primary purpose of the factory method is to instantiate objects and return them.

Download the complete chapter:

  • Chapter 2: Factory method pattern (PDF, 925K)

Model-View-Controller pattern

The Model-View-Controller (MVC) is a compound pattern, or multiple patterns working together to create complex applications. The MVC pattern is most commonly used to create interfaces for software applications—and, as the name implies, consists of three elements:

  • Model: Contains the application data and logic to manage the state of the application
  • View: Presents the user interface and the state of the application onscreen
  • Controller: Handles user input to change the state of the application

The power of the MVC pattern can be directly attributed to the separation of the three elements without overlap in each of their responsibilities.

Download the complete chapter:

  • Chapter 12: Model-View-Controller pattern (PDF, 1.25 MB)

More Like This

  • Creating a preloader in Flash
  • Understanding the changes in the display API in ActionScript 3.0
  • ActionScript 3 Cookbook excerpts: From custom classes to the rendering model
  • ActionScript 3.0 Quick Reference Guide excerpts: Copy motion, display list, events, and migration
  • Tips for learning ActionScript 3.0
  • Developers and designers talk about migrating to ActionScript 3
  • Introduction to event handling in ActionScript 3.0
  • Learning ActionScript 3 excerpts: OOP overview, display list, and programmatic motion
  • Adobe Flash Platform ActionScript reference for RIA development
  • Colin Moock ActionScript 3 videos

Tutorials & Samples

Tutorials

  • Flash iOS Apps Cookbook excerpt: ActionScript optimization
  • Introduction to Robotlegs – Part 3
  • Introduction to Robotlegs – Part 2
  • Introduction to Robotlegs – Part 1

Samples

  • ActionScript 3 samples for Flash Professional CS5

ActionScript Blog

More
06/09/2012 New Flash Tools: Flash Optimizer 2.3
06/09/2012 Flash Optimizer 2.3
05/27/2012 How to add an image to android gallery (CameraRoll) using adobe air
04/22/2012 ActionScript 3.0 BitmapData, Clone, and ColorTransform

ActionScript Cookbook

More
03/20/2012 PDF Portfolio Navigational TOC
02/29/2012 Embed Stage3D content inside Flex application components
02/13/2012 Randomize an array
02/09/2012 Using Camera with a MediaContainer instead of VideoDisplay

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement