State Design Pattern

Learn how to implement the State design pattern in Kotlin.

We'll cover the following...

We can think of the State design pattern as an opinionated Strategy pattern. But, while the Strategy pattern is usually replaced from the outside by the client, the state may change internally based solely on the input it gets.

Look at this dialog a client wrote with the Strategy pattern:

  • Client: Here’s a new thing to do, start doing it from now on.
  • Strategy: OK, no problem.
  • Client: What I like about you is that you never argue with me.

Compare it with this one: ...