Actionscript3 Design Patterns
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
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 used to carry out ‘orders’ like  authenticate user process form sit on cat often encapsulates an algorithm. often performs tricky operations.
Command Pattern Lab
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 and Subscribe. is used in event driven design. reduces coupling between classes, but they can still interact.
Observer Pattern Lab In this lab, we’re going to leverage the Observer Pattern implementation built into the Flash Player. Event Dispatcher Observer Observer Observer
PROXY PATTERN
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. improve communication and understanding between developers so they can work independently and more efficiently.
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 independent  (AS2, AS3, Coldfusion, Java, C#, Perl, Python, PHP, Ruby) Excellent Documentation and Active Development Community Winner at SilvaFUG between 9 frameworks Cairngorm
PureMVC Conceptual Diagram
DSP-IP Contact information Download slides at:  www.dsp-ip.com Course materials & lecture request Projects development services: Adi Yakov Training Manager [email_address] +972-9-8651933 www.dsp-ip.com   Mail  :  [email_address]   Phone:  +972-9-8850956,  Fax  :  +972-50- 8962910 Alona Ashkenazi Development  Services [email_address] +972-9-8850956

ActionScript Design Patterns

  • 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.
  • 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 used to carry out ‘orders’ like authenticate user process form sit on cat often encapsulates an algorithm. often performs tricky operations.
  • 11.
  • 12.
  • 13.
    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 and Subscribe. is used in event driven design. reduces coupling between classes, but they can still interact.
  • 14.
    Observer Pattern LabIn this lab, we’re going to leverage the Observer Pattern implementation built into the Flash Player. Event Dispatcher Observer Observer Observer
  • 15.
  • 16.
    A Proxy… standsin for and provides access to another object. can control or guard access can be used to manage instantiation
  • 17.
    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
  • 18.
    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
  • 19.
    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
  • 20.
  • 21.
    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
  • 22.
  • 23.
    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
  • 24.
  • 25.
    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
  • 26.
    MODEL VIEW CONTROLLERA collection of patterns
  • 27.
    Model View Controller(MVC) The MVC Pattern is a collection of patterns used to address the challenges presented by rich user interfaces.
  • 28.
    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. improve communication and understanding between developers so they can work independently and more efficiently.
  • 29.
    Quick Comparison ModelView Controller Command Façade Proxy Mediator Observer Notification Model View Controller Command Delegate Service CairngormEvent Cairngorm
  • 30.
    What I LikeAbout PureMVC Platform independent (AS2, AS3, Coldfusion, Java, C#, Perl, Python, PHP, Ruby) Excellent Documentation and Active Development Community Winner at SilvaFUG between 9 frameworks Cairngorm
  • 31.
  • 32.
    DSP-IP Contact informationDownload slides at: www.dsp-ip.com Course materials & lecture request Projects development services: Adi Yakov Training Manager [email_address] +972-9-8651933 www.dsp-ip.com Mail : [email_address] Phone: +972-9-8850956, Fax : +972-50- 8962910 Alona Ashkenazi Development Services [email_address] +972-9-8850956

Editor's Notes

  • #4 Improve the development workflow since they help to capture ideas with metaphors that are easy to understand and talk about. The code is separated into manageable pieces which teams can work on separately and can clearly communicate about. The code is well defined so that when change happens, you can adjust your patterns or introduce new patterns to deal with the change.
  • #5 Architectural Patterns are larger in scale than design patterns. layers multi-tier runs on a distributed system MVC runs on a single system Pipeline SOA – service oriented architecture: communication by passing data from one service to another Algorithm solve computational problems
  • #7 Many objects we only need one of: caches, DragManager, PopUpManager,
  • #28 If you search the web for MVC frameworks, you’ll find hundreds of options. Each has their own strengths and weaknesses.