想记住自己的学习的点滴,亲。
Creating and Destroying Objects
Item 1: static factory methods
1,One advantage of static factory methods is that, unlike constructors, they have names. 代码的可读性。
2,对于相同参数列表的构造函数,且需要多个构造方法时,显得别扭,只能改变参数的列表,此时使用不同名字的静态工厂方法更加合理。
3,每次调用方法时,不必创建一个新的对象(跟一般的构造函数比较,单例自然也可以做到)
4,A third advantage of static factory methods is that, unlike constructors, they can return
an object of any subtype of their return type.(灵活,可以吧实现类给隐藏掉)