Spring SALE
Chain of Responsibility

Chain of Responsibility in Swift

Chain of Responsibility is behavioral design pattern that allows passing request along the chain of potential handlers until one of them handles request.

The pattern allows multiple objects to handle the request without coupling sender class to the concrete classes of the receivers. The chain can be composed dynamically at runtime with any handler that follows a standard handler interface.

Complexity:

Popularity:

Usage examples: The Chain of Responsibility is pretty common in Swift. It’s mostly relevant when your code operates with chains of objects, such as filters, event chains, etc.

Identification: The pattern is recognizable by behavioral methods of one group of objects that indirectly call the same methods in other objects, while all the objects follow the common interface.

The following examples are available on Swift Playgrounds.
Kudos to Alejandro Mohamad for creating the Playground version.

Chain of Responsibility in Other Languages

Chain of Responsibility in C# Chain of Responsibility in C++ Chain of Responsibility in Go Chain of Responsibility in Java Chain of Responsibility in PHP Chain of Responsibility in Python Chain of Responsibility in Ruby Chain of Responsibility in Rust Chain of Responsibility in TypeScript