Completed code for the factory pattern