Design Patterns

advertisement
Design Patterns
Patterns
• Patterns take you from a bunch of unrelated pieces to a
finished product
1
Design Patterns
• Strategies for you “toolbox of ideas”
• Templates for solutions
• Codified “best practices”
2
Design Patterns are NOT
• Architectural styles (design patterns are too low-level)
• Code libraries (design patterns are ideas, not code)
peer to peer
3
Design Patterns: Primary Goals
• To help maintainability, flexibility, and other quality attributes
• Help system designers make good decisions
• There are a few dozen OO patterns
• There are other patterns for non-OO systems
• Design patterns based on their structure and purpose
• NOT language
4
Design Patterns
•
•
•
•
•
•
•
•
•
5
Builder
Factory method
Prototype
Singleton
Adapter
Bridge
Composite
Decorator
Façade
•
•
•
•
•
•
•
•
Flyweight
Proxy
Interpreter
Mediator
Memento
Observer
Strategy
Template method
Design Patterns
•
•
•
•
•
•
•
•
•
6
Builder
Factory method
Prototype
Singleton
Adapter
Bridge
Composite
Decorator
Façade
• Flyweight
•Creational
Proxy
• Patterns
Interpreter
• Mediator
• Memento
• Observer
• Strategy
• Template method
Builder Design Pattern
• Separates object construction from representation
• Provides way to create complex objects
• E.g., building a car with different options
7
Factory Method Design Pattern
• Creates objects without specifying exact class, deferring
instantiation to subclasses
8
Prototype Design Pattern
Clones an existing object from a prototype
May be more efficient then creating a new object
9
Singleton Design Pattern
• Restricts object to one instance with a single point of access
10
Design Patterns
•
•
•
•
•
•
•
•
•
11
Builder
Factory method
Prototype
Singleton
Adapter
Bridge
Composite
Decorator
Façade
• Flyweight
• Proxy
• Interpreter
• Mediator
• Memento
• Observer
• Strategy
• Structural
Template method
Patterns
Adapter Design Pattern
• Wraps interface of one object around the incompatible
interface of another object, to allow both objects to work
together
12
Bridge Design Pattern
• Separates an abstraction from its implementation
13
Composite Design Pattern
• Composes several objects into a tree structure so they can act
uniformly
14
Decorator Design Pattern
• Adds or overrides responsibilities dynamically
15
Façade Design Pattern
• Provides a unified interface to subsystems
16
Flyweight Design Pattern
• Similar objects share data/state to avoid creating and
manipulating many objects
17
Proxy Design Pattern
• Provides placeholder for another object to control access
18
Design Patterns
• Builder
• Factory method
• Prototype
• Singleton
• Adapter
• Bridge
• Composite
• Behavioral
Decorator
Patterns
• Façade
19
•
•
•
•
•
•
•
•
Flyweight
Proxy
Interpreter
Mediator
Memento
Observer
Strategy
Template method
Interpreter Design Pattern
• Implements special language by representing grammar to
interpret sentences in the language
20
Mediator Design Pattern
• Defines an object to encapsulate how a set of objects interact,
providing only that object with detailed knowledge of other
objects
21
Memento Design Pattern
• Restores an object to its previous state
22
Observer Design Pattern
• Publish / subscribe, allowing several objects to see an event
and change state appropriately
23
Strategy Design Pattern
• Selects one of a family of algorithms at runtime
24
Template Method Design Pattern
• Defines an algorithm’s skeleton, then subclasses provide
concrete behavior
25
Design Patterns
• Literally books written on this subject…
• The “Bible” of Design Patterns
26
Next Steps..
• Homework #3 (Architecture) do FRIDAY!!
• Vision Statement Peer Review is 11/11
• Midterm due 11/25
27
Download