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.

  1. Creational Design Pattern - helps instantiate objects
  2. Structural Design Pattern - helps organize relationships between objects
  3. 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: 

  1. Mediator Design Pattern  : Defines simplified communication between classes.
  2. Memento Design Pattern : Capture and restore an object’s internal state.
  3. Interpreter Design Pattern : A way include language elements in a program.
  4. Iterator Design Pattern : Sequentially access the elements of a collection.
  5. Chain of Responsibility Design Pattern  :  A way of passing a request between chains of objects.
  6. Command Design Pattern : Encapsulate a command request as an object.
  7. State Design Pattern : Alter an object’s behavior when its state changes.
  8. Strategy Design Pattern : Encapsulates an algorithm inside a class.
  9. Observer Design Pattern : A way of notifying change to a number of class.
  10. Template Method : Defer the exact steps of an algorithm to a subclass.
  11. 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 :

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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. 

Comments

Popular posts from this blog

Sorting Algorithms - JAVA👽

Object Oriented Programming - JAVA- class boundary, variable types, modifiers, java main method

Object Oriented Programming - JAVA- Method Overriding