Вы находитесь на странице: 1из 2

Design Patterns Cheat Sheet

Creational Patterns Structural Patterns (cont’d)


Abstract Factory Bridge

Provides an interface for creating families of related or dependent objects without Decouples an abstraction from its implementation so that the two can vary
specifying their concrete classes independently
Abstraction
AbstractFactory ConcreteFactory Client
+Operation()
+CreateProductA() +CreateProductA()
+CreateProductB() +CreateProductB() ConcreteImplementorA

creates
Client +OperationImpl()
Implementor
ProductA
AbstractProduct +OperationImpl() ConcreteImplementorB
ProductB +OperationImpl()

Builder
Composite
Separates the construction of a complex object from its representation so that the
same construction process can create different representations. Composes objects into tree structures to represent part-whole hierarchies

Composite
Director Builder
+Operation()
+Construct() +BuildPart() +Add(component)
Component
+Remove(component)
+Operation() +GetChild(index)
Client +Add(component)
Product builds ConcreteBuilder +Remove(component)
+GetChild(index) Leaf
+BuildPart()
+Operation()

Factory Method
Decorator
Defines an interface for creating an object but let subclasses decide which class to
instantiate Attaches additional responsibilities to an object dynamically

Product Creator ConcreteComponent


+FactoryMethod() +Operation()
Component
+Operation() ConcreteDecorator
Decorator
ConcreteProduct creates ConcreteCreator +Operation()
+Operation() +AddedBehavior()
+FactoryMethod()

Prototype Facade

Specifies the kinds of objects to create using a prototypical instance and create new Provides a unified interface to a set of interfaces in a subsystem
objects by copying this prototype
Facade
ConcretePrototype1
+Clone()
Prototype
Client
+Clone() Subsystem
ConcretePrototype2
+Clone()
Flyweight

Singleton Uses sharing to support large numbers of fine-grained objects efficiently

Ensure a class only has one instance and provide a global point of access to it
FlyweightFactory
Client
+GetFlyweight(key)
Singleton
-instance UnsharedFlyweight
+Operation(state)
-Singleton() Flyweight
+GetInstance()
+Operation(state)
Flyweight
+Operation(state)
Structural Patterns
Adapter
Proxy
Converts the interface of a class into another interface clients expect
Provides a surrogate or placeholder for another object to control access to it

Target Proxy
Client
+Request() +Request()
Subject
Client
+Request()
Adapter Adaptee RealSubject
+Request() +SpecificRequest() +Request()
Design Patterns Cheat Sheet
Behavioral Patterns Behavioral Patterns (cont’d)
Chain of Responsibility Observer

Avoids coupling the sender of a request to its receiver by giving more than one object Defines a one-to-many dependency between objects so that when one object changes
a chance to handle the request state all its dependents are notified and updated automatically

ConcreteHandler1 Subject
Observer
+HandleRequest() +Attach(observer)
Handler +Detach(observer) +Update()
Client +Notify()
+HandleRequest()
ConcreteHandler2
+HandleRequest()
ConcreteSubject ConcreteObserver
-subjectState -observerState

Command +HandleRequest() +Update()

Encapsulates a request as an object, thereby letting you parameterize clients with


different requests, queue or log requests, and support undoable operations State

Client Invoker Allows an object to alter its behavior when its internal state changes

executes Context
+Request()
Receiver ConcreteCommand Command
+Action() +Execute() +Execute()
ConcreteStateA
+Handle()
State
Interpreter
+Handle()
ConcreteStateB
Given a language, defines a representation for its grammar along with an interpreter
that uses the representation to interpret sentences in the language +Handle()

Client Context
Strategy
TerminalExpression Defines a family of algorithms, encapsulate each one, and make them interchangeable
+Interpret(context)
AbstractExpression
+Interpret(context) Context
NonterminalExpression
+ContextInterface()
+Interpret(context)
StrategyA

Iterator +AlgorithmInterface()
Strategy

Given a language, defines a representation for its grammar along with an interpreter +AlgorithmInterface()
StrategyB
that uses the representation to interpret sentences in the language
+AlgorithmInterface()

Aggregate ConcreteAggregate
+CreateIterator() +CreateIterator() TemplateMethod

Client Defines the skeleton of an algorithm in an operation, deferring some steps to


subclasses
Iterator
ConcreteIterator
+First() AbstractClass
+Next() +Next() ConcreteClass
+CurrentItem() +TemplateMethod() +PrimitiveOperation1()
+PrimitiveOperation1() +PrimitiveOperation2()
+PrimitiveOperation2()
Mediator

Defines an object that encapsulates how a set of objects interact TemplateMethod

Represents an operation to be performed on the elements of an object structure


Mediator ConcreteMediator

Visitor ConcreteVisitor
ConcreteColleague1
Colleague +VisitElementA(element) +VisitElementA(element)
+VisitElementB(element) +VisitElementB(element)
ConcreteColleague2

Client ConcreteElementA
Memento +Accept(visitor)
Element
Without violating encapsulation, capture and externalize an object's internal state so +Accept(visitor)
that the object can be restored to this state later ConcreteElementB
+Accept(visitor)
Originator Memento
-state -state
Caretaker
+SetMemento(memento) +GetState()
+CreateMemento() +SetState()

Вам также может понравиться