Design Pattern — Behavioural — Low level system design — Strategy, , Observer, State design pattern (part 4)

Chetan Dwarkani
2 min readJan 18, 2023

Behavioural design pattern is concerned with identifying common communication pattern between objects and separating them into different classes which can be plugged in any of the other objects and help in inter-communicating.

Before we dive into a complete explanation. I’d strongly suggest understanding the other blogs I added on Creational, Structural design patterns to be studied. Please find the blog link below

Now, let’s go ahead with Behavioural design pattern

Strategy:

When there is a certain algorithm which is common across various other classes and objects then abstracting that algorithm into pluggable objects makes it easy for the object to communicate. This is where the strategy pattern comes into the picture.

Example: Let’s say we are implementing a session and token strategy to authenticate our incoming request. Then the below code would help you to understand how the Strategy pattern suggests you code in order to have a better code reusability

Observer Design Pattern:

The observer design pattern is a very common pattern across the industry which comes into the picture when a lot of objects are to be updated when an event is triggered. This pattern says to create a generic class which keeps a note on the list of observers and whenever an event is received, all the observers listening to the event should be updated.

Below code-example explains well on the same

State Design Pattern:

A lot of time we come across the situation where there is a state transition involved between objects and status is required to be known when we are in a particular object. This design pattern explains well about the same.

Example:

Let’s say we have 3 class for a courier which is order -> order receieved -> payment receieved. At any stage, we may wanna know ship progress, verify order payments or say cancel order. On Basis of that, our code can be well arranged in the below format which gives us a clear abstraction for order status at any stage.

--

--

Chetan Dwarkani

Tech experience in System Design | Java Script Framework | Android framework | ReactJS | JAVA | DB Design | chetandwarkani.com