© Dmitri Nesteruk 2020
D. NesterukDesign Patterns in .NET Core 3https://doi.org/10.1007/978-1-4842-6180-4_10

10. Decorator

Dmitri Nesteruk1  
(1)
St. Petersburg, c.St-Petersburg, Russia
 

Suppose you’re working with a class your colleague wrote, and you want to extend that class’ functionality. How would you do it, without modifying the original code? Well, one approach is inheritance: you make a derived class, add the functionality you need, maybe even override something, and you’re good to go.

Right, except this doesn’t always work, and there are many reasons why. The most common reason is that you cannot inherit the class – either because your target class needs to inherit something else (and multiple inheritance is impossible) or because the class ...

Get Design Patterns in .NET Core 3: Reusable Approaches in C# and F# for Object-Oriented Software Design 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.