Idioms and Patterns

Download Report

Transcript Idioms and Patterns

Idioms and Patterns
•
•
•
•
polymorphism -- inheritance and delegation
idioms -- realizing concrete types
patterns -- a catalogue of design patterns
events -- the reactor pattern
Additional keywords and phrases:
generic types, assertions, canonical
classes, event-driven computation
Postacademische Cursus Informatie Technologie
vrije Universiteit
amsterdam
A catalogue of design patterns
Subsections:
Creational Patterns
Structural Patterns
Behavioral Patterns
Postacademische Cursus Informatie Technologie
vrije Universiteit
amsterdam
A Catalogue of Design Patterns
•
•
•
•
a common design vocabulary
documentation and learning aid
an adjunct to existing methods
a target for redesign
Postacademische Cursus Informatie Technologie
vrije Universiteit
amsterdam
The Pattern Schema
Name - handle
increases design vocabulary
Problem - when to apply
explains the problem and the conflict
Solution - general arrangement
design, responsibilities, collaborations
Consequences - tradeoffs
to understand the costs and benefits
Postacademische Cursus Informatie Technologie
vrije Universiteit
amsterdam
design for change
Causes for Redesign
• creating an object by specifying a class explicitly -- Abstract Factory,
Factory Method, Prototype
• dependence on specific operations -- Chain of Responsibilty, Command
• dependence on hardware & software platforms -- Abstract Factory, Bridge
• dependence on object implementation or representation --Abstract Factory,
Bridge, Memento, Proxy
Postacademische Cursus Informatie Technologie
vrije Universiteit
amsterdam
• algorithm dependence -- Iterator, Strategy, Template Method, Visitor
• extending functionality by subclassing -- Bridge, Composite, Decorator,
Observer
• tight coupling -- Abstract Factory, Bridge, Chain of Responsibilities,
Command, Facade, Mediator, Observer
• inability to alter classes conveniently -- Adaptor, Decorator,
Postacademische Cursus Informatie Technologie
vrije Universiteit
amsterdam
Creational Patterns
Postacademische Cursus Informatie Technologie
vrije Universiteit
amsterdam
Creational Patterns
•
•
•
•
Factory -- hide concrete classes
Factory Method -- virtual constructors
Prototype -- dynamic creation by cloning
Singleton -- one instance only
Postacademische Cursus Informatie Technologie
vrije Universiteit
amsterdam
Structural Patterns
object and class composition
Pattern
Composite
Flyweight
Adaptor
Bridge
Decorator
Facade
Proxy
Postacademische Cursus Informatie Technologie
Alias
Remarks
part/whole
collections of components
part/whole*
extrinsic state, many objects
wrapper
resolves inconsistencies
handle/body abstraction to implementation
wrapper
to introduce functionality
wrapper*
provides unified interface
surrogate
to defer ... remote, virtual,
protection
vrije Universiteit
amsterdam
Behavioral Patterns
cooperation
algorithms and the assignment of responsibilities between objects
class
Template Method -- the skeleton of an algorithm
Interpreter -- to evaluate expressions
object
composition
Mediator -- provides indirection
Chain of Responsibility -- connect objects to interact
Observer -- to handle dependencies
Postacademische Cursus Informatie Technologie
vrije Universiteit
amsterdam
Encapsulating behavior
•
•
•
•
•
objectify!
Command -- action + undo
Strategy -- choice of algorithms
Visitor -- decouple traversal and operations
Iterator -- access and traversal
State -- object state -> behavioral change
Postacademische Cursus Informatie Technologie
vrije Universiteit
amsterdam
The Observer Pattern
Observer
one-to-many dependencies and
notification
Consequences
abstract coupling between subject
and observer
constraint propagation
deals with unexpected updates
Postacademische Cursus Informatie Technologie
vrije Universiteit
amsterdam
Postacademische Cursus Informatie Technologie
vrije Universiteit
amsterdam