Behavioral Design Pattern - Software Engineering
Behavioral Design Pattern - Software Engineering 👽
In the industry we have to use Design Patterns to develop systems. There are 3 types of design patterns.
- Creational Design Pattern - helps instantiate objects
- Structural Design Pattern - helps organize relationships between objects
- Behavioral Design Pattern - helps solve communication problems between objects
In here we will discuss about Behavioral Design Pattern.
Behavioral Design Patterns
- Behavioral patterns focus on the interactions between cooperating objects.
- Behavioral design patterns are concerned with the interaction and responsibility of objects.
- Behavioral patterns only concern about the communication between the objects.
- The interaction between the object should be in such a way that they can talk to each other easily and should be loosely coupled.
- That means the implementation and the client should be loosely coupled avoid any hard coding or dependencies.
- The interaction between the cooperating object is loosely coupled and the loose coupling is the key to the anterior architecture.
Some behavioral design patterns:
- Mediator Design Pattern : Defines simplified communication between classes.
- Memento Design Pattern : Capture and restore an object’s internal state.
- Interpreter Design Pattern : A way include language elements in a program.
- Iterator Design Pattern : Sequentially access the elements of a collection.
- Chain of Responsibility Design Pattern : A way of passing a request between chains of objects.
- Command Design Pattern : Encapsulate a command request as an object.
- State Design Pattern : Alter an object’s behavior when its state changes.
- Strategy Design Pattern : Encapsulates an algorithm inside a class.
- Observer Design Pattern : A way of notifying change to a number of class.
- Template Method : Defer the exact steps of an algorithm to a subclass.
- Visitor Design Pattern : Defines a new operation to a class without change.
A trick to remember Behavioral Design Patterns :
2 MICS On TV (MMIICCSSOTV)
(Copy from CODE)
Some behavioral design patterns & their cooperating objects :
- Observer Pattern
- Subject (Observable) - This object provides the data or state that other objects are interested in.
- Observer - This object registers with the subject to be notified when the subject's state changes.
- Strategy Pattern
- Context – This object holds a reference to a specific strategy object and uses it to perform an operation.
- Concrete Strategy – This object implements the specific algorithm or behavior that the context will delegate the task to.
- Command Pattern
- Command - This object encapsulates a request as an object.
- Invoker - This object triggers the command object, initiating the request.
- Receiver - This object performs the action triggered by the command.
- Mediator Pattern
- Mediator - This object acts as a central communication hub, facilitating communication between other objects.
- Colleagues - These objects represent individual participants that rely on the mediator for communication.
- Chain of Responsibility Pattern
- Handler - This object in the chain receives a request and decides either to handle it or pass it on to the next handler in the chain.
Where to use Behavioral Design Pattern :
- Used in many modern systems for send/receive protocol.
- Used in client-server communications.
- Used in event nus and integration layers.
- Used for iterating data structure.
Advantages :
- Increases the flexibility in carrying out communication.
- Makes your code more flexible, reusable and maintainable.
- Reduces sub-classing.
- Reduces the dependencies between objects and establish loose coupled.
Blogs that you can refer to improve your knowledge about Design Patterns.
- https://miyurangika1223.blogspot.com/2024/09/design-patterns.html (Design Patterns)
- https://miyurangika1223.blogspot.com/2024/12/StructuralDesignPattern.html (Structural Design Pattern)
- https://miyurangika1223.blogspot.com/2025/01/CreationalDesignPattern.html (Creational Design Pattern)
Comments
Post a Comment