Adding problem 3, factory using inheritance.