Added a factory that creates the objects for the three subclasses.