Chain of responsibility

A useful pattern you need to be familiar with is the Chain of Responsibility pattern so we will use it as an example. With this pattern, we will set up a collection or chain of classes for handling a request. The idea is the request will pass through each class until it is handled. This illustration uses a car service center, where each car will pass through the different sections of the center until the service is complete.

Let's start by defining a collection of flags that will be used to indicate the services required:

[Flags]enum ServiceRequirements{    None = 0,    WheelAlignment = 1,    Dirty = 2,    EngineTune = 4,    TestDrive = 8}
The FlagsAttribute in C# is a great way of using a bit field to hold a collection of flags. ...

Get Hands-On Design Patterns with C# and .NET Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.