State pattern: Why doesn't the context class implement or inherit the State abstract interface/class
Posted
by Ricket
on Stack Overflow
See other posts from Stack Overflow
or by Ricket
Published on 2010-05-28T17:55:35Z
Indexed on
2010/05/28
18:02 UTC
Read the original article
Hit count: 334
design-patterns
|state-pattern
I'm reading about the State pattern. I have only just begun, so of course I begin by reading the entire Wikipedia article on it.
I noticed that both of the examples in the article have some base abstract class or Java interface for a generic State's methods/functions. Then there are some states which inherit from the base and implement those methods/functions in different ways. Then there's a Context class which has a private member of type State and which, at any time, can be equal to an instance of one of the implementations. That context class also implements the same methods, and passes them onto the current state instance, and then has an additional method to change the state (or depending on design I understand the change of state could be a reaction to one of the implemented methods).
Why doesn't this context class specifically "extend" or "implement" the generic State base class/interface?
© Stack Overflow or respective owner