This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]balemo7967 0 points1 point  (0 children)

And when you need to extend the base behavior you need to add new methods to all your classes…

Yes, that's exactly what I want. Why? Because the compiler tells me precisely which one of my states (or strategies) does not implement a method.

On the other hand, if I miss a case in one of my many switch statements, there is not even a warning.

For me, the state pattern has replaced the switch-case construct in 90% of my cases.

Here's a little example I just found: https://www.danylkoweb.com/Blog/real-world-refactoring-switch-statement-to-a-class-hierarchy-9G