Behavioral Design Pattern deals with how objects interact. It describes how objects communicates with each other and how the steps of a task is broken among different objects so as to provide more flexibility and make the code more testable.
If you are looking for something specific, you can jump right into the relevant section from here.
- Chain Of Responsibility Design Pattern
- Command Design Pattern
- Iterator Design Pattern
- Mediator Design Pattern
- Memento Design Pattern
- Observer Design Pattern
- State Design Pattern
- Strategy Design Pattern
- Template Design Pattern
- Visitor Design Pattern
Chain of Responsibility is a behavioural design pattern that let us pass the requests among a chain of handlers where each handler decides either to process the request or to pass it along the chain.
In Command pattern, the class that executes the command(called Invoker) is decoupled from the class which produces the command(ConcreteCommand) and from the class that knows how to perform it.(Receiver)
This pattern is used for iterating over a collection of elements. It does not expose the data structure used in implementing it (array, dictionary or linked list) rather it gives an interface which iterates over the collection of elements without exposing its underlying representation.
Let us take a scenario when two or more classes has to interact with each other. Instead of directly communicating with each other and getting the knowledge of their implementation, they can talk via a Mediator.
Memento Pattern captures the current state of an object and store it in such a way that you can retrieve it at a later time when you would like to return to the previous state.
In this pattern, one object notifies other objects about its state change i.e. when the state of one object changes, other object which are subscribed to it gets notified about the state change. So, it is a one-to-many relationship. The object whose state changes are called observable or subject and the objects which subscribe for changes on the observable are called observers.
State design pattern is a design pattern where an object needs to change his behavior when its internal state has changed. It appears as if the object changed its class.
This pattern defines a family of algorithms: each one of them written in a separate class allowing us to select which algorithm to execute at runtime.
In this pattern, the base class defines the template of an algorithm and let the subclass implement these abstract methods in the same way they are defined in the base class without changing the overall structure.
Visitor design pattern separates the algorithms from the objects on which they operate i.e. the operational logic is moved from each elements of a group into a new class. The new class will perform the operational logic using the data from those elements.
For more, check the Medium Blog