Behavioural Patterns Flashcards
What is the purpose of the ‘Chain of Responsibility’ pattern?
To avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.
What is the purpose of the ‘Command’ pattern?
To encapsulate a request as an object, thereby letting you parameterise clients with different requests, queue or log requests, and support undoable operations.
What is the purpose of the ‘Iterator’ pattern?
To provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
What is the purpose of the ‘Memento’ pattern?
To capture and externalise an object’s internal state, without violating encapsulation, so that it can be restored to this state later.
What is the purpose of the ‘Observer’ pattern?
To define a one-to-many dependency between objects so that when one object changes its state, all its dependants are notified and updated automatically.
What is the purpose of the ‘Strategy’ pattern?
To define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
What is the purpose of the ‘Template Method’ pattern?
To define the skeleton of an algorithm in a method, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure.