By WalkingTree October 28th, 2020
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.
In the last blog and webinar on State Management in Flutter, we learned about managing state using Stateful…
In this week’s blog on plugins, we will look at a very special requirement – OCR(Optical Character Recognition)…
When choosing plugins to achieve device related functionalities, always prefer the plugins developed by the flutter.dev author or…
Flutter is great with device-related functionalities and, in most cases, there are plugins available to handle different native…
Data represented in a tabular format is easy to understand and interpret. Tabular data also makes effective use…