© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
D. NesterukDesign Patterns in .NET 6https://doi.org/10.1007/978-1-4842-8245-8_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, and maybe even override something, and you’re good to go.

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

Get Design Patterns in .NET 6: 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.