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
Tuesday, January 12, 2016
Large Conditionals in Static Factory Methods
Thursday, January 7, 2016
Validation via Static Typing
Furthermore, most type system lack means to statically describe types such as “a list with at least two elements” or “a floating-point number larger than or equal to zero”.http://programmers.stackexchange.com/a/258281
Such requirements should be described as far as possible using static typing; anything else has to be worked around via run-time validation.
Subscribe to:
Posts (Atom)