Byte 1: define the state as an enum

Some time ago I had some free time and was looking over the codebase of one of the apps I’m working on and something caught my eye, the constructor looked something like:

From this code, you would get the impression that you could have 8 possible states of the class, but that wasn’t the case, the screen could/should have only one state at any given moment as you can’t come from the login and from the signup screen at the same time.

Fast forward end of the day, the class was looking something like:

Lesson to be learned? If you need to express a state try and use a single variable to define it.




Leave a Comment

Blog