I read about the state template. I just started, so of course I start by reading the entire Wikipedia article about this.
I noticed that both examples in the article have a base abstract class or Java interface for common State methods / functions. Then there are some states that inherit from the base and implement these methods / functions in different ways. Then there is the Context class, which has a private member of the state type and which at any time can be equal to an instance of one of the implementations. This context class also implements the same methods and passes them to the current instance of the state, and then has an additional method of changing the state (or depending on the design, I understand that changing the state may be a reaction to one of the implemented methods).
Why does this context class not specifically “extend” or “implement” a common base class / database interface?
source
share