Refactoring the factory class