PRACTICAL DESIGN PATTERNS

Simple Strategy Pattern Using Attributes

How to improve from traditional branching and understanding how the strategy pattern brings down cyclomatic complexity.

Nicklas Millard
Published in
7 min readJan 4, 2021

--

Illustration by Nicklas Millard
Illustration by Nicklas Millard

Are you struggling with the strategy pattern, or want an extra “take” on how you might go about applying it?

Hopefully, by the end of this article, you’ll have a crisp understanding of how the strategy pattern works, why it’s useful, and perhaps even recognize how custom C# attributes can add value to your application.

Let me just say this right from the get-go, even if your main language is JavaScript, Python, or something obscure like Swift, then I’m sure you’ll find something useful here. You don’t need to be a C# developer to get thru this article.

The strategy pattern is likely one of those first design patterns you’ll ever try to implement yourself. You’ve possibly already implemented this pattern a ton of times before by simply using traditional branching techniques, such as a switch or if-else statements.

While that works fine in many cases, chances are you’ll need to improve your codebase’s internal code qualities at some point. You can typically translate branching statements into objects, whereby…

--

--

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.