mardi 24 avril 2018

Java - why would one use the state design pattern over saving the state in a variable?

I am very new to Java so excuse me if this sounds like a dumb question.

Why is such a big effort made when following the state-design-pattern (creating an interface, context and concrete sub-classes for each state) when you could just save the state of a given object in a variable and then make decisions based on switch and if-else statements later on?

Aucun commentaire:

Enregistrer un commentaire