APPLIED DESIGN PATTERNS

This Is How You Extend Your Classes Without Modifying Them

Plain and simple extension over modification using decorators

The Startup
Published in
5 min readJun 2, 2020

--

Ever had new requirements thrown at you where you’d need to add new functionality to a class — even if it’s probably not the class’ main responsibility?

Say you’re told to add some log traces in a repository class. Easy, receive a logger object in the constructor and slap those log statements in there. A week later you need to add caching functionality, now, you’re starting to bloat the constructor and method complexity rises.

It’s quite possible that it’ll go on like this.

You want a way out of this increasing maintainability nightmare. Preferably a simple, easy way out.

In this article we’re looking into the following

👉 Extract an interface to apply the decorator pattern
👉 Extend a class’ functionality without modifying it
👉 Register the decorated class with a Dependency Container

Let’s put an end to the madness with a very simple, lightweight decorator pattern

--

--

The Startup

I mostly write to "future me" sharing what I learn and my opinion on software development practices. youtube.com/@nmillard | open for contracts in Jan 2026.