Design Patterns Flashcards
Creational Patterns
Used to construct objects such that they can be decoupled from their implementing system.
Structural Patterns
Used to form large object structures between many disparate objects.
Behavioural Patterns
Used to manage algorithms,
relationships, and responsibilities between objects.
Object Scope
Deals with object relationships that can be
changed at runtime.
Class Scope
Deals with class relationships that can be changed at compile time.
Creational Patterns (5)
- Abstract Factory
- Builder
- Factory Method
- Prototype
- Singleton
Structural Patterns (7)
- Adapter
- Bridge
- Composite
- Decorator
- Facade
- Flyweight
- Proxy
Behavioural Patterns (11)
- Chain of Responsibility
- Command
- Interpreter
- Iterator
- Mediator
- Memento
- Observer
- State
- Strategy
- Template Method
- Visitor
Chain of Responsibility Purpose
Gives more than one object an opportunity to handle a request
by linking receiving objects together.
Use Chain of Responsibility When
- Multiple objects may handle a request and the handler
doesn’t have to be a specific object. - A set of objects should be able to handle a request with the
handler determined at runtime. - A request not being handled is an acceptable potential
outcome.
Command Purpose
Encapsulates a request allowing it to be treated as an object.
This allows the request to be handled in traditionally object-based relationships such as queuing and callbacks.
Use Command When
- You need callback functionality.
- Requests need to be handled at variant times or in variant orders.
- A history of requests is needed.
- The invoker should be decoupled from the object handling the
invocation.
Interpreter Purpose
Defines a representation for a grammar as well as a mechanism
to understand and act upon the grammar.
Use Interpreter When
- There is grammar to interpret that can be represented as
large syntax trees. - The grammar is simple.
- Efficiency is not important.
- Decoupling grammar from underlying expressions is desired.
Iterator Purpose
Allows for access to the elements of an aggregate object
without allowing access to its underlying representation.
Use Iterator When
- Access to elements is needed without access to the entire
representation. - Multiple or concurrent traversals of the elements are needed.
- A uniform interface for traversal is needed.
- Subtle differences exist between the implementation details
of various iterators.
Mediator Purpose
Allows loose coupling by encapsulating the way disparate sets of
objects interact and communicate with each other. Allows for the
actions of each object set to vary independently of one another.
Use Mediator When
- Communication between sets of objects is well defined
and complex. - Too many relationships exist and common point of control
or communication is needed.
Memento Purpose
Allows for capturing and externalizing an object’s internal
state so that it can be restored later, all without violating
encapsulation.
Use Memento When
- The internal state of an object must be saved and restored
- Internal state cannot be exposed by interfaces without exposing
implementation. - Encapsulation boundaries must be preserved.
Observer Purpose
Lets one or more objects be notified of state changes in other
objects within the system.