DESIGN PATTERNS SERIES

How to manage states with State Design Pattern in C#?

Everything you need to know about State Design Pattern in C# in one place.

Daniel Rusnok
.NET Core
Published in
5 min readMay 7, 2020

--

Dog Class and its states in c#.
Original image created by Katemangostar

The state as a term

At its necessary, we can say that the state can be defined as the condition of something changeable. Early in our education years, we learned standard states of matter — solid, liquid, and gas. We learned that each state has different properties and behaviors.

As software developers, we must take care of the different states of the applications. With more states comes more code to tame them. Without proper design, we can quickly end up in the big world of decision-making statements.

Boolean Flag Pattern

Boolean Flag Pattern is not the official name of the pattern, but I think that a more significant half of you recognize a meaning. When the developer finds out that he can or can’t do something in a particular state, he will introduce a boolean flag and use the…

--

--

Daniel Rusnok
.NET Core

Senior Software Developer. Loving to gain & share knowledge. Focused on Microsoft technologies like Azure, .NET Core & C#. Software Architecture enthusiasist.