Consider static factory methods instead of constructors

Advantages:
1.Unlike constructors,they have names.
2.Unlike constructors,they are not required to create a new object each time they are invoked.
3.Unlike constructors,they can return an object of any subtype of their return type.
4.Reduce the verbosity of creating parameterized type instances

Disadvantages:
The main disadvantages of providing only static factory methods is that classes without public or protected constructors can not be subclassed.
A second disadvantages of static factory methods is that they are not readily distinguishable from other static methods.

你可能感兴趣的:(Constructor)