-
Notifications
You must be signed in to change notification settings - Fork 273
10. 原型模式
Landy.Liu edited this page May 18, 2019
·
1 revision
所谓原型模式,就是 Java 中的克隆技术,以某个对象为原型。复制出新的对象。显然新的对象具备原 型对象的特点,效率高(避免了重新执行构造过程步骤)。数据内容相同,但对象实例不同(完全两个个体)
原型模式就是从一个对象再创建另外一个可定制的对象,而且不需要知道任何创建的细节。
- Apache BeanUtils利用反射实现对象属性值的复制,就是利用了原型模式。
- Spring中的原型模式:把对象中的依赖关系,在每次使用对象之前,都会创建一个新的对象,并且将依赖关系完整的复制给新创建的对象。(scope="prototype")
Spring 默认是采用单例模式
SegmentFault: https://segmentfault.com/u/landy8530
简书:https://www.jianshu.com/u/36a7d3a994ac
CSDN:https://blog.csdn.net/landy8530
开源中国:https://my.oschina.net/landy8530
微信公众号:蚂蚁与咖啡的故事