

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Creational Patterns
Abstract Factory
Provides an interface for creating families of related or dependent objects without specifying their concrete classes
Client
ConcreteFactory
AbstractProduct ProductB
ProductA
+CreateProductA() +CreateProductB()
AbstractFactory
+CreateProductA() +CreateProductB()
Structural Patterns Adapter
Converts the interface of a class into another interface clients expect
Client
Adapter
+Request()
Target
+Request()
Adaptee
+SpecificRequest()
Structural Patterns (cont’d)
creates
Singleton
Ensure a class only has one instance and provide a global point of access to it
Singleton
-instance
-Singleton() +GetInstance()
Builder
Separates the construction of a complex object from its representation so that the same construction process can create different representations.
Director
+Construct()
Builder
+BuildPart()
ConcreteBuilder
+BuildPart()
Product builds
Factory Method
Defines an interface for creating an object but let subclasses decide which class to instantiate
Product
ConcreteProduct
Creator
+FactoryMethod()
ConcreteCreator
+FactoryMethod()
creates
Prototype
Specifies the kinds of objects to create using a prototypical instance and create new objects by copying this prototype
Client
ConcretePrototype
+Clone() Prototype
+Clone() (^) ConcretePrototype
+Clone()
Proxy
Provides a surrogate or placeholder for another object to control access to it
Subject
+Request()
Client
RealSubject
+Request()
Proxy
+Request()
Flyweight
Uses sharing to support large numbers of fine-grained objects efficiently
Flyweight
+Operation(state)
FlyweightFactory
+GetFlyweight(key)
Flyweight
+Operation(state)
UnsharedFlyweight
+Operation(state)
Client
Bridge
Decouples an abstraction from its implementation so that the two can vary independently
Client
Abstraction
+Operation()
ConcreteImplementorA
+OperationImpl() Implementor
+OperationImpl() (^) ConcreteImplementorB
+OperationImpl()
Composite
Composes objects into tree structures to represent part-whole hierarchies
Client
Component
+Operation() +Add(component) +Remove(component) +GetChild(index) Leaf
+Operation()
Composite
+Operation() +Add(component) +Remove(component) +GetChild(index)
Decorator
Attaches additional responsibilities to an object dynamically
Component
+Operation() Decorator
+Operation()
ConcreteComponent
+Operation()
ConcreteDecorator
+Operation() +AddedBehavior()
Facade
Provides a unified interface to a set of interfaces in a subsystem
Facade
Subsystem
Behavioral Patterns
Chain of Responsibility
Avoids coupling the sender of a request to its receiver by giving more than one object a chance to handle the request
Client
ConcreteHandler
+HandleRequest() Handler
+HandleRequest() (^) ConcreteHandler
+HandleRequest()
Command
Encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations
Client Invoker
Command
+Execute()
ConcreteCommand
+Execute()
Receiver
+Action()
Interpreter
Given a language, defines a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language
Client Context
TerminalExpression
+Interpret(context) AbstractExpression
+Interpret(context) NonterminalExpression
+Interpret(context)
Iterator
Given a language, defines a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language
Client
Aggregate
+CreateIterator()
ConcreteAggregate
+CreateIterator()
Iterator
+First() +Next() +CurrentItem()
ConcreteIterator
+Next()
Mediator
Defines an object that encapsulates how a set of objects interact
Mediator
Colleague
ConcreteColleague
ConcreteColleague
ConcreteMediator
Memento
Without violating encapsulation, capture and externalize an object's internal state so that the object can be restored to this state later
Caretaker
Originator
+SetMemento(memento) +CreateMemento()
Memento
+GetState() +SetState()
Behavioral Patterns (cont’d) Observer
Defines a one-to-many dependency between objects so that when one object changes state all its dependents are notified and updated automatically
Observer
+Update()
Subject
+Attach(observer) +Detach(observer) +Notify()
ConcreteSubject
-subjectState
ConcreteObserver
-observerState
State
Allows an object to alter its behavior when its internal state changes
State
+Handle()
ConcreteStateA
+Handle()
ConcreteStateB
+Handle()
Context
+Request()
Strategy
Defines a family of algorithms, encapsulate each one, and make them interchangeable
Strategy
+AlgorithmInterface()
StrategyA
+AlgorithmInterface()
StrategyB
+AlgorithmInterface()
Context
TemplateMethod
Defines the skeleton of an algorithm in an operation, deferring some steps to subclasses
AbstractClass
+TemplateMethod() +PrimitiveOperation1() +PrimitiveOperation2()
ConcreteClass
+PrimitiveOperation1() +PrimitiveOperation2()
TemplateMethod
Represents an operation to be performed on the elements of an object structure
Client
Visitor
+VisitElementA(element) +VisitElementB(element)
ConcreteElementA
+Accept(visitor) Element
+Accept(visitor) ConcreteElementB
+Accept(visitor)
ConcreteVisitor
+VisitElementA(element) +VisitElementB(element)
executes
-state -state
+HandleRequest() +Update()
+ContextInterface()