By WalkingTree   October 28th,  2020

Chain of Responsibility in Dart and Flutter

Chain of Responsibility (COR), also known as Chain of Command, is a behavioral design pattern wherein its primary purpose is to rework the basic workflow and split it into different parts or objects. The Chain of Responsibility allows reordering, adding, and removing handlers in the chain. Also, each handler can be implemented in a way that it could decide whether to pass the request further down the chain or not. 

A typical COR structure consists of:

  • Handler: It defines the interface for handling requests.
  • BaseHandler: An abstract class that contains the boilerplate code which is common to all the handler classes. 
  • ConcreteHandlers: Contains the actual code.
  • Client: It composes the chain of handlers and later initiates the request to a ConcreteHandler object.

When to use Chain of Responsibility in Flutter?

The COR design pattern should be used when the system has to process different kinds of requests. But neither the request types nor the handling sequence is defined at compile-time. The COR pattern enables linking several handlers into one chain and allows the client to pass requests along the chain. Each handler receives the request and processes it. 

This pattern can also be used when a single request must be handled by multiple handlers. In such a case, the chain could be defined at compile-time and all requests will get through the chain as planned.

Read on to know more about the Chain of Responsibility design pattern and how it can be implemented in a Flutter framework.

Blogs

Translate »
Privacy Preferences
When you visit our website, it may store information through your browser from specific services, usually in form of cookies. Here you can change your privacy preferences. Please note that blocking some types of cookies may impact your experience on our website and the services we offer.