Skip to content

Comment on Stop Writing If-Else Trees: Use the State Pattern Instead

Comments

This is a domain modeling question.

If your if-else branches and flags are creating a combinatorial explosion and/or allowing more states to exist than are valid, pay the complexity tax of introducing a State pattern - it will pay itself back in maintainability and lack of bugs over time.

But if you’re just talking about one or two standalone values, the state is already there, represented as simply as possible by your enums.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.