ActionScript Design Patterns


Published on

This course review design patterns in ActionScript3 as well as two known MVC platforms for Actionscript: PureMVC and Corringham

Published in: Technology, Education
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • 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.
  • 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
  • Many objects we only need one of: caches, DragManager, PopUpManager,
  • If you search the web for MVC frameworks, you’ll find hundreds of options. Each has their own strengths and weaknesses.
  • ActionScript Design Patterns

    1. 1. Actionscript3 Design Patterns
    2. 2. Quick Overview <ul><li>You’re going to learn about a number of design patterns. </li></ul><ul><li>You’re going to work out some of them in code. </li></ul><ul><li>You’re going to apply most of the patterns we learn today towards an example Model View Controller application </li></ul>
    3. 3. Design Patterns… <ul><li>Are reusable solutions to common design problems </li></ul><ul><li>Improve the development workflow </li></ul><ul><li>Help teams to work together efficiently </li></ul><ul><li>Help you deal with change </li></ul>
    4. 4. Design Patterns… <ul><li>are not Algorithms </li></ul><ul><li>are not Architectural Patterns </li></ul><ul><li>are not finished designs </li></ul><ul><li>are not written in stone </li></ul>
    5. 5. Singleton Pattern <ul><li>The one and only </li></ul>
    6. 6. The Singleton Pattern… <ul><li>has only ONE instance ever </li></ul><ul><li>is created only when needed </li></ul><ul><li>assures that every object in an application is using the same resource (global access point) </li></ul>
    8. 8. Singleton Pattern Tips <ul><li>Use this pattern when you need one and only one instance of a class </li></ul><ul><li>The package mx.managers are all singletons </li></ul><ul><ul><li>DragManager </li></ul></ul><ul><ul><li>CursorManager </li></ul></ul><ul><ul><li>HistoryManager </li></ul></ul><ul><ul><li>FocusManager </li></ul></ul><ul><ul><li>etc… </li></ul></ul>
    9. 9. COMMAND PATTERN <ul><li>Execute Here  </li></ul>
    10. 10. The Command Pattern… <ul><li>encapsulates method invocation. </li></ul><ul><li>is used to carry out ‘orders’ like </li></ul><ul><ul><li>authenticate user </li></ul></ul><ul><ul><li>process form </li></ul></ul><ul><ul><li>sit on cat </li></ul></ul><ul><li>often encapsulates an algorithm. </li></ul><ul><li>often performs tricky operations. </li></ul>
    11. 11. Command Pattern Lab
    13. 13. The Observer Pattern… <ul><li>defines a one to many relationship between objects so when one object changes, all the observers are notified. </li></ul><ul><li>is also known as Publish and Subscribe. </li></ul><ul><li>is used in event driven design. </li></ul><ul><li>reduces coupling between classes, but they can still interact. </li></ul>
    14. 14. 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
    15. 15. PROXY PATTERN
    16. 16. A Proxy… <ul><li>stands in for and provides access to another object. </li></ul><ul><li>can control or guard access </li></ul><ul><li>can be used to manage instantiation </li></ul>
    17. 17. The Virtual Proxy <ul><li>The Virtual Proxy stands in for an object that </li></ul><ul><li>is expensive to create </li></ul><ul><li>is not immediately available </li></ul><ul><li>The Loader class is a Virtual Proxy. </li></ul>DisplayObjectContainer Loader Sprite Stage MovieClip
    18. 18. The Remote Proxy <ul><li>The Remote Proxy stands in for a remote object and, </li></ul><ul><li>delegates requests to a remote object </li></ul><ul><li>manages communication with remote object </li></ul>Image Search Flickr API Remote PhotoProxy Remote Service Your Application
    19. 19. Proxy Pattern Lab <ul><li>In this lab, we’re going to implement a remote proxy and learn about a time saving technique. </li></ul>Image Search Flickr API Remote PhotoProxy Remote Service Your Application
    20. 20. FAÇADE PATTERN <ul><li>Hiding Complexity </li></ul>
    21. 21. Façade Pattern… <ul><li>The Façade pattern simplifies access to a collection of objects. </li></ul><ul><li>Often implemented as a singleton (only need one) </li></ul><ul><li>Hides the complexity of underlying objects </li></ul>Application Facade Model View Controller
    22. 22. ADAPTER PATTERN <ul><li>a.k.a. Wrapper </li></ul>
    23. 23. Adapter Pattern… <ul><li>The Adapter pattern converts and translates the API of one object to the API of another object. </li></ul><ul><li>often applied when reusing legacy code </li></ul><ul><li>providing a common API to several 3 rd party libraries or algorithms </li></ul>Music Player MP3 Adapter FLAC Adapter AC3 Adapter FLAC Decoder MP3 Decoder WAV Decoder
    24. 24. Mediator Pattern <ul><li>Central Communication </li></ul>
    25. 25. Mediator Pattern <ul><li>The Mediator Pattern is used to centralize complex communication and control between related objects. </li></ul>Application Username Textbox Password Textbox Submit Button New Account Form Account Form Mediator
    26. 26. MODEL VIEW CONTROLLER <ul><li>A collection of patterns </li></ul>
    27. 27. Model View Controller (MVC) <ul><li>The MVC Pattern is a collection of patterns used to address the challenges presented by rich user interfaces. </li></ul>
    28. 28. Model View Controller (MVC) <ul><li>MVC brings order to applications and application development by, </li></ul><ul><li>decoupling the user interface of an application from the data model and business logic. </li></ul><ul><li>allow each of the elements to be changed without impacting the other. </li></ul><ul><li>improve communication and understanding between developers so they can work independently and more efficiently. </li></ul>
    29. 29. Quick Comparison <ul><li>Model </li></ul><ul><li>View </li></ul><ul><li>Controller </li></ul><ul><li>Command </li></ul><ul><li>Façade </li></ul><ul><li>Proxy </li></ul><ul><li>Mediator </li></ul><ul><li>Observer </li></ul><ul><li>Notification </li></ul><ul><li>Model </li></ul><ul><li>View </li></ul><ul><li>Controller </li></ul><ul><li>Command </li></ul><ul><li>Delegate </li></ul><ul><li>Service </li></ul><ul><li>CairngormEvent </li></ul>Cairngorm
    30. 30. What I Like About PureMVC <ul><li>Platform independent (AS2, AS3, Coldfusion, Java, C#, Perl, Python, PHP, Ruby) </li></ul><ul><li>Excellent Documentation and Active Development Community </li></ul><ul><li>Winner at SilvaFUG between 9 frameworks </li></ul>Cairngorm
    31. 31. PureMVC Conceptual Diagram
    32. 32. DSP-IP Contact information Download slides at: Course materials & lecture request Projects development services: Adi Yakov Training Manager [email_address] +972-9-8651933 Mail : [email_address] Phone: +972-9-8850956, Fax : +972-50- 8962910 <ul><ul><li>Alona Ashkenazi </li></ul></ul><ul><li>Development Services </li></ul><ul><li>[email_address] +972-9-8850956 </li></ul>