Reference types, Value types, and Patterns
- slide 28 : 29
Examples of Static Factory Methods
In class
Point
it may be relevant to construct both polar and rectangular points
A clumsy attempt with two overloaded constructors.
A better solution with static factory methods.
In struct
Interval
it would be natural to have a parameterless constructor, but it is illegal
A clumsy attempt with two overloaded constructors and an illegal constructor.
A better solution with static factory methods.
Chose a coding style in which
factory methods
are consistently named:
Make...(...)