When creating groups of related classes, it's important to maintain those relationships during object creation. One way to do this is with the Factory Method design pattern. The Factory Method pattern is a creational pattern and solves the problem of creating objects without specifying a concrete type. This is most often used in abstract classes that define a method for object creation. Subclasses can then override this method to define the specific object to be created. The Factory Method is most often used in conjunction with another pattern called the Template Method. To better understand the Factory Method and provide more context for this solution, we'll also look at the Template Method in this chapter. Because the Factory Method uses and then builds on many of the same concepts, we'll look at the Template Method first. |