Monday, December 18, 2006

"Actionscript 3.0 Design Patterns" - Joey Lott

Joey Lott preparing for his session at FOTB

An eagerly awaited session as Joey has basically written the book(s) on ActionScript. I was surprised by how young he was. Cool jersey by the way Joey!

  • This session won't be entertaining or funny. It will be dry, we'll cover a lot of ground and there'll be a lot of code in it.

  • What are design patterns?

    • Elegant solutions to common problems

    • Guidelines

    • Shared language

  • Why use design patterns?

    • Don't reinvent the wheel

    • Work smarter and faster

    • Communicate more efficiently

  • "Design Patterns: Elements of Reusable Design" - recommended book as a starting place for design patterns

  • Pitfalls of using Design Patterns

    • Designpatternitis

      • Turning apps into design pattern stew

      • Using patterns inappropriately for the sake of it

    • Over-complication

    • Inflexibility

  • Important Fundamentals of Design Patterns

    • Programming to an interface/polymorphism

    • Understanding abstract classes

    • Using inheritance and composition

    • Architecture 101

      • Discreet groupings

      • Keep to 1-3 responsibilities for a class

  • 1. MVC - Model Viewer Control pattern

    • Remove data from representation of the data and again from the control of the data

    • Model - just store data

    • View - displays it

    • Control - allows different views

  • 2. Singleton pattern

    • One managed instance of a class in your app

    • Creating it as a public static and gets it from class using public static method

    • Constructor never called from outside class

    • Can force this using an internal "enforcer" class

  • 3. Iterator

    • Puts all the iterative processing behind an interface to force a it be done the same way - forces a common language

    • So if you want to do something different (i.e. get stuff in reverse) create a new iterator which also uses the interface so commands called are all the same

    • Iterator can then be swapped out at runtime without breaking!

  • 4. Command

    • Similar but for commands

    • E.g.

      • ICommand - execute()

      • IRedoableCommand - redo()

      • IUndoableCommand - undo()

    • Keep history (call stack of instances) and just call undo() in each - simple and easy!

  • 5. Memento

    • Missed most of this as dropped my pen and spent most of the time on the floor looking for it - eventually remember another one in my coat pocket!

    • Made up of...

      • Originator

      • Caretaker

      • Memento

    • E.g.

      • Memento tells radius and colour of circle

      • Originator - creates circle object and gets rad and col from the memento

      • Caretaker - main class, instantiates the originator with the memento values

    • This is a bit muddled because of the pen incident

  • 6. Decorator

    • Allows permutations

    • Put decorators on the top of each other to keep extending them

    • Decorators can be a direct inheritance or creating using an abstract class in a real object and passing it into different decorators and getting a modified one in return (this sounds a bit muddled but his example was ace)

      • Shape (abstract) > Circle (shape) > Blue (deco) > Bevel (deco) > Size (deco)

      • MyBevel = new BevelClass(myShape);

    • His book sounds good: "Advanced ActionScript 3 with Design Patterns"


No comments: