Chain of responsibility
medium 45 minA request travels past several handlers until one takes it, or until one stops it.
Watch lesson4:36
UML design
Classes, the link, and the path of five tickets.
The point: one abstract class holds the walking, four small classes hold the rules, and one function holds the order.
Classes
The support desk
Support desk
1/4Entry
The ticket interface knows one handler and calls handle.
usesdepends onextends (is a)
next, drawn as a row. The next one is not owned: a handler does not create or destroy its successor.Reading the diagram
- 1
Interface
setNextlinks,handleprocesses or passes. All handlers look alike, so any order can be built. - 2
Base class
Holds
nextand the default forwarding. Without it every team would repeat three lines, and one would forget the null check. - 3
Concrete handlers
Each class holds one rule and its own action. A change of the medium rule touches
Level2only. - 4
Request
The ticket is data and does not change on its way. Handlers that write into a shared request depend on each other in secret.
- 5
Linkage
The list ends where
nextis empty. Termination is either a taker or the end.
Over time
Two journeys
LOW stops early, UNKNOWN goes to the end