Pattern Extensibility
Let’s say we want to add a new state to the program—for example, a checkout state in which all of our purchases are totaled. This is simple enough to do:
- Create a new subclass derived from State.
- Call the new subclass CheckoutState or something like that.
- Give this subclass a set of capabilities.
- Define an implementation file for CheckoutState.
- Include the file in the code that manipulates EcommerceEngine.
The steps above point out that we’re basically cloning and modifying the code for one of the existing states. Once your basic states are working, you get the benefit of that investment when you clone one for a new subclass.