Quick Overview You’re going to learn about a number of design patterns.  You’re going to work out some of them in code.  You’re going to apply most of the patterns we learn today towards an example Model View Controller application
Design Patterns… Are reusable solutions to common design problems Improve the development workflow Help teams to work together efficiently Help you deal with change
Design Patterns… are not Algorithms are not Architectural Patterns  are not finished designs are not written in stone
Singleton Pattern The one and only
The Singleton Pattern… has only ONE instance  ever is created only when needed assures that every object in an application is using the same resource (global access point)
Singleton Pattern Lab We’re going to implement an Asset Manager. Application Asset Manager Images Sound
Singleton Pattern Tips Use this pattern when you need  one and only one  instance of a class The package mx.managers are all singletons  DragManager CursorManager HistoryManager FocusManager etc…
Command Pattern Execute Here  
The Command Pattern… encapsulates method invocation. is a class used to carry out an ‘order’ authenticate user process form sit on cat often encapsulates an algorithm. often performs tricky operations.
The Command Pattern… Separating functionality into command classes makes it straight forward to implement complex operations. Undo and Redo Queue or Pipeline Deferred and transactional execution
Command Pattern Lab Create Several Commands that encapsulate visual manipulations of your choice (rotate, scale, swap display list location etc).  User gestures will execute these commands.
Observer Pattern
The Observer Pattern… defines a one to many relationship between objects so when one object changes, all the observers are notified. is also known as Publish/Subscribe, and Listener. is used in event driven design. reduces coupling between classes, but they can still interact.
Observer Pattern Lab Event Dispatcher Observer Observer Observer In this lab, we’re going to leverage the Observer Pattern implementation built into the Flash Player.
Proxy Pattern May I Help You?
A Proxy… stands in for and provides access to another object. can control or guard access can be used to manage instantiation
The Virtual Proxy The Virtual Proxy stands in for an object that  is expensive to create is not immediately available The Loader class is a Virtual Proxy. DisplayObjectContainer Loader Sprite Stage MovieClip
The Remote Proxy The Remote Proxy stands in for a remote object and,  delegates requests to a remote object manages communication with remote object Image Search Flickr API Remote  PhotoProxy Remote Service Your Application
Proxy Pattern Lab In this lab, we’re going to implement a remote proxy and learn about a time saving technique. Image Search Flickr API Remote  PhotoProxy Remote Service Your Application
Façade Pattern Hiding Complexity
Façade Pattern… The Façade pattern simplifies access to a collection of objects. Often implemented as a singleton  (only need one) Hides the complexity of underlying objects Application Facade Model View Controller
Adapter Pattern a.k.a. Wrapper
Adapter Pattern… The Adapter pattern converts and translates the API of one object to the API of another object. often applied when reusing legacy code providing a common API to several 3 rd  party libraries or algorithms Music Player MP3 Adapter FLAC Adapter AC3 Adapter FLAC Decoder MP3 Decoder WAV Decoder
Mediator Pattern Central Communication
Mediator Pattern The Mediator Pattern is used to centralize complex communication and control between related objects. Application Username  Textbox Password Textbox Submit Button New Account Form Account Form Mediator
Model View Controller A collection of patterns
Model View Controller (MVC) The MVC Pattern is a collection of patterns used to address the challenges presented by rich user interfaces.
Model View Controller (MVC) MVC brings order to applications and application development by, decoupling the user interface of an application from the data model and business logic.  allow each of the elements to be changed without impacting the other. promotes reusability between UI components and data objects.
Quick Comparison Model View Controller Command Façade Proxy Mediator Observer Notification Model View Controller Command Delegate Service CairngormEvent Cairngorm
What I Like About PureMVC Platform & language independent  mobile, server, browser, desktop AS2, AS3, ColdFusion, C#, Java, Perl, PHP, Python, more  Excellent Documentation and Active Community Programmed to Interfaces Winner at SilvaFUG between 9 frameworks Cairngorm
PureMVC Conceptual Diagram
PureMVC - Model
PureMVC - View
PureMVC - Controller
PureMVC - Notifications
Good Practice Interfaces Design Approach Further Reading
Interfaces There are (hidden) two layers to every class you write Interface Implementation
Designing Applications
Recommended Reading O’Reilly Head First Design Patterns

Design Pattern with Actionscript

  • 1.
  • 2.
    Quick Overview You’regoing to learn about a number of design patterns. You’re going to work out some of them in code. You’re going to apply most of the patterns we learn today towards an example Model View Controller application
  • 3.
    Design Patterns… Arereusable solutions to common design problems Improve the development workflow Help teams to work together efficiently Help you deal with change
  • 4.
    Design Patterns… arenot Algorithms are not Architectural Patterns are not finished designs are not written in stone
  • 5.
  • 6.
    The Singleton Pattern…has only ONE instance ever is created only when needed assures that every object in an application is using the same resource (global access point)
  • 7.
    Singleton Pattern LabWe’re going to implement an Asset Manager. Application Asset Manager Images Sound
  • 8.
    Singleton Pattern TipsUse this pattern when you need one and only one instance of a class The package mx.managers are all singletons DragManager CursorManager HistoryManager FocusManager etc…
  • 9.
  • 10.
    The Command Pattern…encapsulates method invocation. is a class used to carry out an ‘order’ authenticate user process form sit on cat often encapsulates an algorithm. often performs tricky operations.
  • 11.
    The Command Pattern…Separating functionality into command classes makes it straight forward to implement complex operations. Undo and Redo Queue or Pipeline Deferred and transactional execution
  • 12.
    Command Pattern LabCreate Several Commands that encapsulate visual manipulations of your choice (rotate, scale, swap display list location etc). User gestures will execute these commands.
  • 13.
  • 14.
    The Observer Pattern…defines a one to many relationship between objects so when one object changes, all the observers are notified. is also known as Publish/Subscribe, and Listener. is used in event driven design. reduces coupling between classes, but they can still interact.
  • 15.
    Observer Pattern LabEvent Dispatcher Observer Observer Observer In this lab, we’re going to leverage the Observer Pattern implementation built into the Flash Player.
  • 16.
    Proxy Pattern MayI Help You?
  • 17.
    A Proxy… standsin for and provides access to another object. can control or guard access can be used to manage instantiation
  • 18.
    The Virtual ProxyThe Virtual Proxy stands in for an object that is expensive to create is not immediately available The Loader class is a Virtual Proxy. DisplayObjectContainer Loader Sprite Stage MovieClip
  • 19.
    The Remote ProxyThe Remote Proxy stands in for a remote object and, delegates requests to a remote object manages communication with remote object Image Search Flickr API Remote PhotoProxy Remote Service Your Application
  • 20.
    Proxy Pattern LabIn this lab, we’re going to implement a remote proxy and learn about a time saving technique. Image Search Flickr API Remote PhotoProxy Remote Service Your Application
  • 21.
  • 22.
    Façade Pattern… TheFaçade pattern simplifies access to a collection of objects. Often implemented as a singleton (only need one) Hides the complexity of underlying objects Application Facade Model View Controller
  • 23.
  • 24.
    Adapter Pattern… TheAdapter pattern converts and translates the API of one object to the API of another object. often applied when reusing legacy code providing a common API to several 3 rd party libraries or algorithms Music Player MP3 Adapter FLAC Adapter AC3 Adapter FLAC Decoder MP3 Decoder WAV Decoder
  • 25.
  • 26.
    Mediator Pattern TheMediator Pattern is used to centralize complex communication and control between related objects. Application Username Textbox Password Textbox Submit Button New Account Form Account Form Mediator
  • 27.
    Model View ControllerA collection of patterns
  • 28.
    Model View Controller(MVC) The MVC Pattern is a collection of patterns used to address the challenges presented by rich user interfaces.
  • 29.
    Model View Controller(MVC) MVC brings order to applications and application development by, decoupling the user interface of an application from the data model and business logic. allow each of the elements to be changed without impacting the other. promotes reusability between UI components and data objects.
  • 30.
    Quick Comparison ModelView Controller Command Façade Proxy Mediator Observer Notification Model View Controller Command Delegate Service CairngormEvent Cairngorm
  • 31.
    What I LikeAbout PureMVC Platform & language independent mobile, server, browser, desktop AS2, AS3, ColdFusion, C#, Java, Perl, PHP, Python, more Excellent Documentation and Active Community Programmed to Interfaces Winner at SilvaFUG between 9 frameworks Cairngorm
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
    Good Practice InterfacesDesign Approach Further Reading
  • 38.
    Interfaces There are(hidden) two layers to every class you write Interface Implementation
  • 39.
  • 40.
    Recommended Reading O’ReillyHead First Design Patterns