This chapter covers the State pattern.
GoF Definition
Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
Concept
The concept is best described by the following examples.
Real-Life Example
Consider the scenario of a network connection, say a TCP connection. An object can be in various states; for example, a connection might already be established, a connection might be closed, or the object has already started listening through the connection. When this connection receives a request from other objects, it responds as ...