Behavioral Design Patterns Flashcards
Provide definition for Chain of Responsibility
Behavioral design pattern that lets
you pass requests along a chain of handlers. Upon receiving a
request, each handler decides either to process the request or
to pass it to the next handler in the chain
What is not standard approach of Chain Of Responsibility design pattern
Upon receiving a request, a handler decides whether it can process it. If it can, it doesn’t pass
the request any further. So it’s either only one handler that
processes the request or none at all.
Request has to be sent to first handler in the chain (Chain of Responsibility pattern) or not?
Request can be sent to any handler in the chain—it doesn’t
have to be the first one
How to modify the order of handlers in CoR pattern in runtime
If you plan to modify chains at runtime,
you need to define a setter for altering the value of the reference field
Chain of Responsibility is often used in conjunction with Composite. How Composite pattern can be adjusted for that
Component need to have a link to composite. This link play a role of next handler. (p.259)
How CoR is connected to the Command pattern
Handlers in Chain of Responsibility can be implemented as
Commands. In this case, you can execute a lot of different
operations over the same context object, represented by a
request.
However, there’s another approach, where the request itself
is a Command object. In this case, you can execute the same
operation in a series of different contexts linked into a chain
Provide a definition of command pattern
Command is a behavioral design pattern that turns a request into a stand-alone object that contains all information about the request. This transformation lets you parameterize
methods with different requests, delay or queue a request’s execution, and support undoable operations
What is Separation Of Concerns principle
Design principle for separating a computer program into distinct sections (layers)
Provide a definition of Iterator pattern
Behavioral design pattern that lets you traverse
elements of a collection without exposing its underlying
representation (list, stack, tree, etc.)
Provide definition for Mediator design pattern
Behavioral design pattern that lets you reduce chaotic dependencies between objects. The pattern restricts direct communications between the objects and forces them to collaborate only via a mediator object
What kind of object can Component pass to Mediator
Components may pass any context as arguments of this method, including their own objects, but only in such a way that no coupling occurs between a receiving component and the sender’s class.
What else can do Mediator instead of keeping references to all components
They manage sometimes their lifecycle
Provide definition for Memento design pattern
Behavioral design pattern that lets you save and
restore the previous state of an object without revealing the
details of its implementation
What are the roles of orginator and caretaker in Memento pattern
Caretaker is an object which makes snapshot and produces memento.
Caretaker is an oblect which can use memento but only via the limited interface, it’s not able to
tamper with the state stored inside the memento.
What is memento object
Value object that acts as a snapshot of the
originator’s state. It’s a common practice to make the memento
immutable and pass it the data only once, via the constructor