Subclassing states
Subclassing a state is pretty easy to do; it's just a matter of figuring out when you need to use it. Say we had a state called Moving
. We could create states that extend Moving
and call them Running
, Walking
, and so on. These would all have functionality in common with Moving
, but would have slight alterations. It wouldn't make sense to duplicate all of the functions that would be in the Moving
state just to slightly change them, so subclassing the Moving
state would make sense in this instance. Let's try it out with a simple experiment.