five minute design patterns

20
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy Decorator

Upload: brennan-stephenson

Post on 30-Dec-2015

43 views

Category:

Documents


0 download

DESCRIPTION

Template Factory Singleton Iterator Adapter Façade Observer Command Strategy Decorator. Five Minute Design Patterns. Doug Marttila Forest and the Trees May 30, 2009. Design Patterns. WTF Not a framework 23 - not all applicable to Flash and Flex You’ve used them. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Five Minute Design Patterns

Five Minute Design PatternsDoug MarttilaForest and the TreesMay 30, 2009

Template

Factory

Singleton

Iterator

Adapter

Façade

Observer

Command

Strategy

Decorator

Page 2: Five Minute Design Patterns

2Forest and the Trees

Design Patterns

• WTF

• Not a framework

• 23 - not all applicable to Flash and Flex

• You’ve used them

Page 3: Five Minute Design Patterns

3Forest and the Trees

Why Patterns Matter• Common language

• CS is good for you

• Speed up your development

• Preexisting documentation

• Refine your solutions

• Explains the why

Page 4: Five Minute Design Patterns

4Forest and the Trees

Best Practices?

• Not really in this presentation

• Beware patterns overload

Page 5: Five Minute Design Patterns

5Forest and the Trees

Best Practices

• Encapsulate what varies

• Program to an interface (or super class)

• Favor composition over inheritance

• Inversion of Control

★ Hollywood principle

Page 6: Five Minute Design Patterns

6Forest and the Trees

Categories of Patterns(Are these useful at all? Not so much.)

• Creational

• Structural

• Behavioral

Page 7: Five Minute Design Patterns

7Forest and the Trees

Template

• Define the skeleton (or invariant parts) of an algorithm in a method, while deferring some steps to subclasses.

• Setup the big picture and leave the details to the person doing the work.

Page 8: Five Minute Design Patterns

8Forest and the Trees

Factory

• Define an interface for creating an object, but let the subclasses decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses

Page 9: Five Minute Design Patterns

9Forest and the Trees

Singleton

• Singleton Pattern ensures a class has only one instance, and provides a global point of access to it.

Page 10: Five Minute Design Patterns

10

Forest and the Trees

Iterator

• The Iterator Pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation

Page 11: Five Minute Design Patterns

11

Forest and the Trees

Adapter

• The Adapter Pattern converts the interface of a class into another interface the clients expect.

• Adapter lets classes work together that couldn'totherwise because of incompatible interfaces.

Page 12: Five Minute Design Patterns

12

Forest and the Trees

Façade•The Façade Pattern provides a unified

interface to a set of interfaces in a subsystem. Facade defines a higher level interface that makes the subsystem easier to use.

•Principle of Least Knowledge - talk only to your immediate friends

Page 13: Five Minute Design Patterns

13

Forest and the Trees

Observer

• The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically.

Page 14: Five Minute Design Patterns

14

Forest and the Trees

Command

• The Command Pattern encapsulates a request as an object, thereby letting you parameterize other objects with different requests, queue or log requests, and support undoable operations.

Page 15: Five Minute Design Patterns

15

Forest and the Trees

Strategy

• The Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from the clients that use it.

Page 16: Five Minute Design Patterns

16

Forest and the Trees

Decorator - last one!

• The Decorator Pattern attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

Page 17: Five Minute Design Patterns

17

Forest and the Trees

More Patterns!!!

• State

• Composite

• Bridge

• Proxy

• Interpreter

• Builder

• Abstract Factory

• Memento

• Prototype

• Visitor

• Mediator

• Chain of Responsibility

• Flyweight

• MVC

Page 18: Five Minute Design Patterns

18

Forest and the Trees

Resources

• Beerfug.com

• http://www.forestandthetrees.com/designPatterns/

• Head First Design Patterns (the best) Java

• GoF (dry, but what started it all)

• ActionScript 3 with Design Patterns (Lott, Patterson)

• ActionScript 3.0 Design Patterns (Sanders, Cumaranatunge)

Page 19: Five Minute Design Patterns

19

Forest and the Trees

Thank You!

Doug Marttila

forestandthetrees.com

[email protected]

beerfug.com (first wednesday of every month, beer + code)

Page 20: Five Minute Design Patterns

Forest and the Trees 20

FoT!