The Factory Method as defined: “Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses“. The main point of using this design pattern is to use an interface to hide the class and use an abstract factory method (from an inherited abstract or concrete class) to create composition of the actual class.
Download the source sample: here
Basically, I created a schedule object that will generate a family schedule. We have an interface class to impose the factory method. Then an Abstract Class to hide the actual initialization of the derived class.
if looked carefully. We can see that once we initialize the Concrete Class – it calls the Abstract Class constructor that defers the process of constructing to the createSchedule() method. This brings more security to our code in terms of the creation of the concrete class, we can use this pattern to create objects that has commonality in terms of its composition (common interface / abstract class).