Factory Pattern

The Factory Pattern allows you to write code to create objects, but the calling method does not have to specify the exact type of object to create.

A simple factory is a class that has a method to create objects. It uses a method that instantiates the appropripriate object based on arguments(s).

Like all good patterns, this one relies on polymorphism - the factory creates a child and returns it to the calling method, which saves it as a reference of the parent.

The basic pattern is simple: Factory Pattern from oodesign.com.

We will go through a ParkingTicketFactory during class.

There are a number of flavors for this pattern: