effective java

effective java在第二章Creating and Destroying Objects
中提到用 静态工厂方法的三个好处:
1.方法名的可读性
2.可以instance-controlled
实现singleton,flyweight模式
实现noinstantiableclass
实现immutable class

我想之所以静态工厂方法能够可以很好的instance-controlled,是因为讲创建的逻辑过程分离到了工厂方法里,能够很好的去controll

3.基于接口编程

jdk中的例子:
Boolean.valueof(),很好的一个flyweight和静态工厂方法的例子
java.util.Collections中就更加典型了,没有public的construtor,都是一些静态方法。特点如下:
noninstantiable
static factory methods
based interface programming along with static inner class。

这一章里引起了我对singleton pattern and flyweight pattern的区别理解
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值