O'Reilly logo

Hands-On Design Patterns with C# and .NET Core by Jeffrey Chilberto, Gaurav Aroraa

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required