Behavioral Design Patterns in Software Design

In the previous article we discussed about in brief about various Software design patterns, their types and why they are helpful in developing a robust software architecture which can be reused. Today we will discuss about behavioral design patterns in OOPs and different types of the behavioral design patterns.

What are behavioral design pattern?

Behavioral pattern concerned with interaction between different objects. Behavioral pattern not only describes the pattern of objects or classes but also the pattern of communication between different objects. Behavioral pattern basically describes the flow of processes. It is a step by step flow of object interaction. It maintains how different objects and classes interact with each other to carry out all processes.

Behavioral pattern uses object compositions rather than inheritance.We use behavioral pattern where a single object could not handle the process but which can be handled by group of objects.

Creational pattern helps in the instantiation of object. Structural pattern helps in the creation of structure of the application and the behavior of the application will be controlled by behavioral pattern.

Different types of the behavioral design patterns

  1. Chain of Responsibility

    The chain of responsibility is a design pattern in which there are multiple handlers which handle the process request. It is typically not possible for one object to process the object sent by other objects. The problem can be resolved with help of Chain of responsibility design pattern. There are multiple processing objects which will handle the process once it is successfully passed from one object to another and it gets passed to the end. Chain of responsibility pattern is applicable where there are multiple objects to handle the processes.There should be more than one object to handle the request. The set of objects which will handle the request should be specified dynamically.
  2. Advantages of Chain of responsibility design pattern

    • Each of the objects is independent of the other. Hence chain of responsibility supports reduced coupling amongst different objects.
    • The codes are more flexible as there are different objects handling different process.
    • As there is no recipient at the end of the process so it is not sure that process will be successfully handled at the end of the process completion.

    Let’s understand this with the help of a real world example.
    Suppose we have a vending machine which accepts coins of any shape and size.In order to do processing of each type of coin we should have specific handlers. The coin of $1 will be handled by one handler and that of 50 Cents will handled by some other handlers. In this way different handlers are used to handle different coins of different weight and size.

  3. Command Pattern

    The command pattern is a design pattern which enables all the information for the request to be stored in a single object.
    Command pattern is a behavioral design pattern in which all information needed to execute a method could be used immediately or held for later use. This object doesn’t execute anything,it only includes information.

    Advantages of the Command design pattern

    • Command pattern supports decoupling as the object implementing the operation and object invoking the functions are unaware of each other.
    • Objects can be easily manipulated and changed.
    • We can easily assemble commands into composite commands
    • It is an easy process to add new commands because we don’t need to change the existing class.

    Suppose we have an oven in which have different functionalities like heating the food, start button, end button, buzzer button. All the functionalities of the oven will be handled by the oven.
  4. Interpreter Pattern

    The interpreter pattern is a design pattern which is used when developing domain-specific languages. This pattern allows the grammar for such domain specific language to be represented in an object-oriented programming.
    Interpreter pattern are applicable where the grammars are simple.
    It basically evaluates the sentence in the languages. The patter is described in term of formal grammar.

    Advantages of interpreter design patterns

    • As the interpreter pattern uses classes to represent language. We can easily use inheritance to change or extend the grammar.
    • Implementation of grammar is easy.
    • Through interpreter pattern we can easily evaluate an expression as per the new requirement.
    • Interpreter can easily handle easy grammar but it is difficult to handle complex grammar.

Read More:
Difference between method Overloading and Overriding in OOPs
How does inheritance work in Java?
Ad-hoc Testing, Monkey Testing & Exploratory Testing
Difference in Drivers and Stubs | Software Testing

Copyright © ianswer4u.com

0 Reactions:

Post a Comment