150 likes | 393 Views
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.
E N D
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
A catalogue of design patterns Subsections: Creational Patterns Structural Patterns Behavioral Patterns
A Catalogue of Design Patterns • a common design vocabulary • documentation and learning aid • an adjunct to existing methods • a target for redesign
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
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
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,
Creational Patterns • Factory -- hide concrete classes • Factory Method -- virtual constructors • Prototype -- dynamic creation by cloning • Singleton -- one instance only
Structural Patterns object and class composition Pattern Alias Remarks Composite part/whole collections of components Flyweight part/whole* extrinsic state, many objects Adaptor wrapper resolves inconsistencies Bridge handle/body abstraction to implementation Decorator wrapper to introduce functionality Facade wrapper* provides unified interface Proxy surrogate to defer ... remote, virtual, protection
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
Encapsulating behavior objectify! • Command -- action + undo • Strategy -- choice of algorithms • Visitor -- decouple traversal and operations • Iterator -- access and traversal • State -- object state -> behavioral change
The Observer Pattern Observer one-to-many dependencies and notification Consequences abstract coupling between subject and observer constraint propagation deals with unexpected updates