Chapter 9. The Simple Factory Pattern
One type of pattern that we see again and again in OO programs is the Simple Factory pattern. A Simple Factory pattern is one that returns an instance of one of several possible classes, depending on the data provided to it. Usually all of the classes it returns have a common parent class and common methods, but each of them performs a task differently and is optimized for different kinds of data. This Simple Factory is not, in fact, one of the 23 GoF patterns, but it serves here as an introduction to the somewhat more subtle Factory Method GoF pattern we'll discuss shortly.
How a Simple Factory Works
To understand the Simple Factory pattern, let's look at the diagram in Figure 9-1.
Figure 9-1. A Simple Factory ...