State
You can think of the State design pattern as an opinionated Strategy pattern, which we discussed at the beginning of this chapter. 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:
- Client: Here's some new input I got from you.
- State: Oh, I don't know. Maybe I'll start doing something differently. Maybe not.
The client should also expect that the state may even reject some of its inputs:
- Client: Here's something for you to ponder, State.
- State: I don't know what it is! Don't you see I'm busy? Go bother some Strategy with this!
So, why do clients...