设计模式-原型模式

 

 

 

 

 

 

 

属性值相同,hashcode不同

在spring框架中的实现:bean.xml

(<bean id="classname" class="com.spring.bean.." scope="prototype"/>)  //原型

 scope="singleton" //单例

applicationContext.getBean("classname")

 

 

 

 

 方法一(重写clone方法)

 

 这种方法可能需要重写很多类的clone方法(级联)

 spring中的BeanUtils.copyProperties();

方法二(通过序列化实现:推荐使用)

 

 

 

 

成员变量在序列化时会重新创建而不是传引用

 

 

 

 

 

posted @ 2019-12-07 15:33  winner66  阅读(79)  评论(0)    收藏  举报