Tuesday, January 12, 2016

Large Conditionals in Static Factory Methods

Create a static factory method with the same parameters as the superclass constructor. It must contain the parameter that will take the starting values of the coded type. Depending on this parameter, the factory method will create objects of various subclasses. To do so, in its code you must create a large conditional but, at least, it will be the only one when it is truly necessary; otherwise, subclasses and polymorphism will do.
https://sourcemaking.com/refactoring/replace-type-code-with-subclasses

No comments:

Post a Comment