Skip to content

NelsonBN/design-patterns-gof-behavioral-state

Repository files navigation

GoF - Behavioral - State

UML Diagram

State

State orquestration

The state pattern isn't opinionated about how the state is orquestrated. We can implement it in three different ways:

  • Orquestrated by the context: The context is responsible for changing the state.
  • Orquestrated by the state: The states are responsible for changing the state to another state/next state.
  • Orquestrated by client: The client is responsible for changing the state. The usualy pass the context as a parameter to the state.

Pros and Cons

  • ✅ Clean code
  • ✅ Single Responsibility Principle
  • ✅ Open/Closed Principle
  • ✅ Easy to add new states
  • ❌ Overkill for simple cases (When there are only a few states)

References

About

GoF - Behavioral - State

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published