Implement loose coupling with Chain of Responsibility Pattern

The chain of responsibility is under the Behavioral Design pattern category. With the Chain of responsibility, you can control the user level. AS a definition we can say that a design pattern that forms a sequentially connected component that looks like a chain. And it helps the consumers to pass the object to the first component. The object will process by each component one after the other as per the sequence (chain).

As an example computer log level info we can take as an example.

Another one is we can take a candidate hiring process (Technical Engineer, Manager, Hr.)

Another one is we can take company level example so in the company each position can assess to each level.

Why we need this implementation because using this implementation we can prevent the loose couple. Because the sender does not know who the receiver is and the receiver does not know who the sender is. The receiver can perform their job without knowing who the sender is. And also Sender can perform their task without knowing who will receive the task is. We can decouple the result using this pattern.

Design Pattern

We can change the receiver and sender without touching the core of the implementation.

Those level examples can be taken for the Chain of responsibility. Now you have a basis for this pattern let’s go for the implementation.

In this pattern, there are some disadvantages also. Here are some of them

  • This can be easily get broken.
  • When a processor calls the wrong processor, it can lead to a cycle.
  • It can create deep stack traces, which can affect the performance.
  • If a processor fails to call the next processor, the command gets dropped.
  • It can lead to duplicate code across processors, increasing maintenance

Real-World example




Associate Software Engineer. |

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Add Some Smarts To Your Change Data Capture

How to Squeeze Test Driven Development on Legacy Systems

D.I.Y. load balancer for GKE on the cheap

Flutter App Development Cost : Factors & Maintenance Cost

iPad Pro apps for students, academics, and researchers.

A Provisional Timeline for the Threshold Merger

Heap Sort Algorithm


Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nisal Jayathilaka

Nisal Jayathilaka

Associate Software Engineer. |

More from Medium

Factory Method Pattern 🏡

Java 11 Features

Test-Driven Development That Every Developer Should Know About (With Example)

Combining cloneable interface with Memento Pattern