Initial Situation

The code controlling an object's state transition are complex.


Replace conditional code with State classes which handle specific states and their transitions.






Reduces or eliminates state-changing conditional code.
Simplifies complex state-changing code.
Provides a better overview of the state-changing code by encapsulating it.
Makes code more complex if state transitions are easy to follow as is.
Setup Continuous Code Quality Management in minutes.

Refactoring Basics

Replace State Altering Conditionals with State

Overview ΒΆ


How to use the Checklist?

Checklists present a proven order of necessary refactoring steps and are especially helpful for beginners.

If you feel comfortable with a refactoring, there is no need to follow each of the steps literally; you can often perform multiple steps at once or skip some.

We suggest to try the recommended order at least once; this will often provide new insights - even for seasoned developers.