Programming in the large

Let's add a feature to our blackjack simulation: analysis of results. We have several paths to implement this added feature. There are two dimensions to the considerations that we must make, leading to a large number of combinations. One dimension is how to design the new features:

  • We can add a function and work out ways to integrate it into the whole.
  • We can use the Command design pattern and create a hierarchy of commands, some of which are single functions and others of which are sequences of functions.

Another dimension of the design that we must consider is how to package the new features:

  • We can write a new top-level script file. This tends to create new commands based on filenames. We might start with commands such as simulate.py and analyze.py.
  • We can add a parameter to an application that allows one script to perform either the simulation or the analysis, or both. We would have commands that look like app.py simulate and app.py analyze.

This leads to four combinations of implementation choices. We'll focus on using the Command design pattern. First, we'll revise our existing application to use the Command design pattern. Then, we'll extend our application by adding features in the form of new command subclasses.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset