The responsibility chain pattern creates a chain of receiver objects for the request. This pattern gives the type of request and decouples the sender and receiver of the request. This type of design pattern belongs to behavioral pattern.
In this pattern, each recipient usually contains a reference to another recipient. If an object cannot process the request, it passes the same request to the next recipient, and so on.
It is hereby recorded that this mode has recently been used in the company's O2O project to dispatch orders according to routing rules.
Here is a simple logic implementation
Responsibility chain abstract base class1 public abstract class RouteBase 2 { 3 private RouteBase _NextRoute = null; 4 public void SetNextRoute(RouteBase routeBase) 5 { 6 _NextRoute = routeBase; 7 } 8 public abstract bool Route(); 9 /// <summary> 10 /// Routing rules 11 /// </summary> 12 public void RouteLink() 13 { 14 if (Route()) 15 { 16 return; 17 } 18 else 19 { 20 _NextRoute.RouteLink(); 21 } 22 } 23 }