What the Factory Design Pattern does

The Factory Design Pattern uses a Factory class to return an instance of one of several possible classes based on the information provided to it.

The essence of this pattern is to place the decision-making logic for what type of class to create in a separate class named the Factory class. The Factory class will then return one of several classes that are all subtle variations of each other, which will do slightly different things based on their specialty. As we do not know what type of class the Factory pattern will return, we need a way to work with any variation of the different types of class returned. This sounds like the perfect scenario for an interface.

To implement our required business functionality, we will create an Infant class, a Child class, and an Adult class. The Infant and Child classes will return false when asked whether they can sign contracts, and the Adult class will return true.