Cheat Sheet
Cheat Sheet
https://reactiveprogramming.io
They devote to collaboration, relationships and responsibility
delegation between classes in order to simplify they manner
in which objects communicate and interact with each other.
Behavioral
Creational Patterns reactiveprogramming.io
Factory Method
Type: Creational
1. The client requests ConcreteFactory for the
creation of ProductA.
Factory Method allows us to create 2. ConcreteFactory finds the concrete
objects from an specific subtype implementation of ProductA and creates a new
through a Factory class. This is instance.
3. ConcreteFactory returns a new
especially useful when we don't ConcreteProductA.
know which subtype we are going 4. The client requests ConcreteFactory for the
to use at design-time, or when do creation of ProductB.
we want to delegate object creation 5. ConcreteFactory finds the concrete
implementation of ProductB and creates a new
logic to a Factory class . instance.
6. ConcreteFactory returns a new
ConcreteProductB.
Singleton
Type: Creational
1. The client requests for an instance of the
It receives this name because it can Singleton through the getInstance
only have a single instance of a method.
specific class for the entire 2. The Singleton checks if the instance has
application; this is achieved by already been created, if not, a new
preventing the creation of multiple instance will be created.
instances of the same class, as it 3. Either the newly created instance or the
typically happens with the new already existing instance is returned.
operator, and imposing a private
constructor and a static method to
get that instance.
Prototype
Type: Creational
1. The client requests for the cloning of prototype
Its functionality is based on object cloning. using the clone method.
New objects are created from a pool of 2. The prototype creates a new instance of itself,
previously created and stored prototypes. using the new operator.
This pattern is especially useful when we 3. The prototype copies all of its own attributes to
need to create objects from existing ones the new instance.
or for creating very large structures of 4. The prototype may clone all the internal objects, a
objects. process that is known as Deep Clone.
5. The newly cloned object is returned by the
prototype.
Command
Type: Behavioral
Observer
Type: Behavioral 1. ObserverA registers into the Observable
object in order to be notified of any
This design pattern allows us to changes.
observe the changes suffered by an 2. ObserverB registers into the Observable
object, that is, if the observed object object in order to be notified of any
suffers any change, a notification changes.
will be sent to the observers; this is 3. The status of the Observable changes.
known as Publish-Subscribe. 4. All the Observers are notified that a
change has occurred.
Template Method
Type: Behavioral
The template design pattern focuses 1. The client creates and gets an instance of the
on code reutilization for implementing template implementation.
steps to solve problems. This is 2. The client executes the templateMethod.
achieved by implementing base classes 3. The default implementation of templateMehod
for defining basic behaviors. Typically, executes the step1, step2, step3, stepN methods in
methods are created for each step of order.
the algorithm; some of these will be 4. The template implementation returns a result.
implemented while others remain
abstract until they are executed by the
subclasses.
Interpreter
1. The client creates the context
Type: Behavioral for the execution of the interpreter.
2. The client creates or gets the expression to be
The Interpreter design pattern is evaluated.
3. The client requests for the evaluation of the
used for evaluating a determined
expression to the interpreter. To that end, it sends
language and return an Expression. it the context.
This pattern can interpret 4. The Expression calls the Non-terminal
languages such as Java, C#, SQL, or Expressions.
5. The Non-terminal Expressions call all the
even a new one invented by us, and
Terminal Expressions.
provide a response based on its 6. The Root Expression requests for the
evaluation. interpretation of a Terminal Expression.
7. The expression is completely evaluated and
provides the result of the interpretation of all the
Terminal and Non-Terminal Expressions.
Memento
1. The Client makes a change to the
Originator.
Type: Behavioral
2. The Originator creates a new Memento
which represents its current state.
It allows us to record the state of an
3. The Client stores the Memento into the
object on a specific moment in
Caretaker in order to change between
order to return it to that state at any
different Originator states.
given time. Memento is useful when
4. After some time, the Client sends a
we have many objects changing
request to the Caretaker for a previous
over time and, for some reason, we
state of the Originator.
need to restore them to a previous
5. The Client uses the Memento sent by
state.
the Caretaker to restore the state of the
Originator.
Null Object
Type: Behavioral 1. The client looks for a specific object.
2. ObjectLookup checks if the requested object
It helps us avoid the appearance of exists.
a. If the requested object doesn't exist, an instance
null values at runtime. What this of NullObject will be returned.
pattern basically proposes is using 3. On the other hand, if the requested object is
instances for implementing the located, an instance of ConcreteObject will be
required interface but with a void returned.
4. The client receives any of the two mentioned
body, instead of returning a null instances, however, it will never get a null reference
value. if the object were not to be found.
State
Type: Behavioral 1. A state by default is set in the Context, this is
StateA.
2. A request operation is executed in the Context,
It changes its behavior depending
delegating the execution to the current state
on the state of the application. To (StateA).
achieve this, a series of classes are 3. The Context changes from StateA to StateB.
created for representing the 4. Again, a request operation is executed in the
Context delegating the execution to the current
different states an application can
state (StateB).
go through, that is, one class for 5. The execution of StateB results in a change to
each state of the application. StateC.
6. A new request operation is executed in the
Context delegating the execution to the current
state (StateC).
Visitor
1. The client creates the structure (Element).
2. The client creates the instance of the Visitor to be
used in the structure.
3. The client executes the accept method of the
Type: Behavioral structure.
4. The Element tells the Visitor which method must be
It separates the logic and operations used for processing each object in the structure.
5. The Visitor analyzes the Element using its
performed over a complex visitElement method and repeats the accept method
structure. On occasions, we can find execution process over the children of the Element.
data structures requiring various 6. ConcreteElementA tells the Visitor which method
operations to be performed and must be used for processing it.
7. The visitor proceeds with the rest of the children of
needing new ones to be created as the Element and executes the accept method on
the application grows. ConcreteElementB.
8. ConcreteElementB tells the Visitor which method
must be used for processing it, that is visitElementB.
9. Lastly, the results are obtained by executing the
getResults method.
Structural Patterns reactiveprogramming.io
Adapter
Type: Structural
It's used when we encounter 1. The Client invokes the Adapter with generic
incompatible software interfaces, parameters.
which, even with this inherent 2. The Adapter converts the generic parameters
incompatibility, have similar into specific parameters for the Adaptee.
3. The Adapter invokes the Adaptee.
features. This pattern is used when 4. The Adaptee answers the call.
we want to work with different 5. The Adapter converts the response of the
interfaces in a homogeneous Adaptee into a generic response for the Client.
manner, to that end, we create an 6. The Adapter attends the Client with a generic
response.
intermediate class which functions
as an adapter.
Bridge
Type: Structural
1. The client executes an AbstraccionImpl operation.
2. AbstraccionImpl relays this petition to
It decouples an abstraction from its ConcreteImplementor, at this point
implementation. The purpose is AbstraccionImpl may convert the parameters
that each one can be modified needed for executing the ConcreteImplementor.
3. ConcreteImplementor returns the results to
separately without affecting the
AbstraccionImpl.
other; in other words, an abstraction 4. The AbstraccionImpl converts the results coming
gets decoupled from its from ConcreteImplementor to give them to the
implementation so they can vary client.
independently.
Composite
Type: Structural 1. The client executes an action over
CompositeA.
It helps us constructing complex 2. Then, CompositeA executes an action
structures from simpler ones; in over CompositeB.
other words, we can use small 3. CompositeB executes an action over
structures to assemble a bigger and LeafA and LeafB and the result is returned
more complex structure. to CompositeA.
4. CompositeA spreads this action over
LeafC, which returns a result.
5. CompositeA gets an end result after an
evaluation of the entire structure, which is
then returned to the client.
Decorator
Type: Structural 1. The client executes an operation over
DecoratorA.
It allows the user to add new 2. DecoratorA executes the same operation over
DecoratorB.
features to an existing object 3. DecoratorB executes an action over
without altering its structure ConcreteComponent.
through the addition of new classes 4. DecoratorB executes a decoration operation.
wrapped around the original one, 5. DecoratorA executes a decoration operation.
6. The Client receives a decorated object by all the
giving it extra capabilities. This Decorators, which have encapsulated the
pattern has been designed to solve Component below many layers.
scenarios where a subclassification
hierarchy cannot be applied.
Facade
Type: Structural
1. The client invokes a facade operation.
It hides the complexity of interacting with a 2. The facade communicates with SubsystemA to
group of subsystems by providing a high perform an operation.
level interface, which is in charge of 3. The facade communicates with SubsystemB to
establishing communication with all the perform an operation.
subsystems, keeping the user from having 4. The facade communicates with SubsystemC to
to directly interact with each system. perform an operation.
5. The facade provides the client with the result of
the operation.
Flyweight
1. The client requests the Factory for the
Type: Structural
creation of a Flyweight object.
2. Before creating the object, the Factory
It's dedicated to building light
checks if there's an identical object to the
objects by abstracting parts that
one being requested, if so, it returns the
can be reused and shared in order
existing object; if not, it will create the new
to create new objects when
object and store it in a cache for further
required, and reusing objects
use.
created by other instances.
3. The Flyweight object is created or
borrowed from the cache and returned to
the client.
Structural Patterns (Continuation) reactiveprogramming.io
Proxy
Type: Structural 1. The client sends a request for an
object to the Factory.
2. The Factory creates a Proxy for encapsulating
It's devoted to the mediation the Object.
between two objects. What I refer 3. The client executes the Proxy, which was created
as mediation is the series of actions by the Factory.
4. The Proxy performs one or more actions before
executed before and after carrying the execution of the Object.
out the task requested by the user. 5. The Proxy hands over the execution to the
Object.
6. The Proxy performs one or more actions after the
execution of the Object.
7. The Proxy returns the result.