DESIGN PATTERN

How to use Chain of Responsibility Pattern

According to Gang of Four, it defines a chain of responsibilities to process a request. In other words, pass the request from one object to another until an object accepts its responsibility.

Sukhpinder Singh | .Net Developer
C# Programming
Published in
3 min readJun 12, 2021

--

Photo by Miguel Á. Padriñán from Pexels

Use Case

Let’s consider an example of a claims system in any corporate company. Here is the list of the price range that can be approved and by whom.

100–1000 Rs => Junior/Senior Engineers => Approved by Manager1001–10000 Rs => Managers => Approved by Senior Manager

If the amount is outside the 10000 range, exceptional approval is required from the senior manager.

The above use case can be easily implemented using the Chain of Responsibility design pattern. So, the claim class has the following properties.

public class Claim{
public int Id{get;set;}
public double amount{get;set;}
}

Prerequisites

  • Basic knowledge of OOPS concepts.
  • Any programming language knowledge.

--

--

Sukhpinder Singh | .Net Developer
C# Programming

Programmer by heart | C# | .Net 6 | .Net 8 | dotnet | dotnetcore | Kubernetes | Angular | AWS | Remember to 👏 Linktree: https://linktr.ee/sukhpindersingh