Like this article? We recommend
Pattern Extensibility
Suppose we want to add a new state to the program; that is, a testing state to allow the instance of EngineEntity to be tested before attempting to forward data. This is simple enough to do:
- Create a new subclass derived from State.
- Call the new subclass TestingState or something similar.
- Give this subclass a set of capabilities.
- Define an implementation file for TestingState.
- Include the file in the code that manipulates EngineEntity.
The preceding steps show that we’re basically cloning and modifying the code for one of the existing states. So after your basic states are working, you get the benefit of that investment when you clone one for a new subclass. You know you’ve got a good solid design when this type of reuse is available!