Class hierarchies are a fundamental feature of object-oriented programming languages. Chapter 3 examined their capabilities. This chapter examines their (often significant) limitations and introduces the more flexible concept of a strategy hierarchy. Strategy hierarchies are a central component of several design techniques. This chapter examines two such techniques—the strategy pattern and the command pattern—and their uses.
The Strategy Pattern
Let’s begin by reviewing the template pattern from Chapter 3. In it, an abstract class (known as the template) provides a skeletal implementation of each public method, ...