The Gang of Four Decorator Pattern

Design patterns can be defined as time-tested solutions, or problem solvers for recurring code problems. At You_Source, we love design patterns as they help us save time communicating about code, architecture, and they help reduce the time developers spend on understanding code (which, according to various studies, developers spend 20% up to 80% doing).

The decorator pattern is one of the easiest Gang of Four pattern to learn and is also one of the most useful. Using a decorator pattern, you can change the flow of an application dynamically without touching the current production (and tested) code. Except of course, where the object or abstraction is instantiated.

If you’d like a free consultation about design patterns, please leave your email address.

In this video we discuss the benefits of the decorator pattern, and show a practical example on how it can be implemented in C#. Since this video is part of our internal C# training program and material, we also made the cheat sheet available which shows you the code used in this video, but also how easy it is to isolate the class in test code.

We will be posting more videos of very basic implementations of the other Gang of Four patterns in the future. If you have preferences which one to do first, please leave them in the comments!

Download the cheatsheet here

  • Joost Pielage

    Really cool video, learned a lot in just 5 minutes. I can’t wait for the rest of the “gang” to show up!