Implementing the Factory Method pattern
We will explore two common implementations of the Factory Method pattern. Each will have design trade-offs, certainly worthy of discussion!
Let’s start with the technique in which the Factory Method is placed in the abstract Product class.
Including the Factory Method in the Product class
To implement the Factory Method pattern, we will first need to create our abstract Product class as well as our Concrete Product classes. These class definitions will begin the foundation on which to build our pattern.
In our example, we will create our Product using a class we are accustomed to seeing – Student
. We will then create Concrete Product classes, namely GradStudent
, UnderGradStudent
, and NonDegreeStudent
. We will include a Factory Method in our Product (Student
) class with a consistent interface to create any of the derived Product types.
The components we will model complement our framework for our existing Student
...