Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > PHP/MySQL/Scripting

  • Print
  • + Share This
Like this article? We recommend

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:

  1. Create a new subclass derived from State.
  2. Call the new subclass CheckoutState or something like that.
  3. Give this subclass a set of capabilities.
  4. Define an implementation file for CheckoutState.
  5. 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.

  • + Share This
  • 🔖 Save To Your Account