设计模式-创建型总结实例(三)
2014-11-24 07:14:46
·
作者:
·
浏览: 2
r.toString(); } @Override protected ConcretePrototype clone() throws CloneNotSupportedException { ConcretePrototype cpBasePrototype = (ConcretePrototype) super.clone(); cpBasePrototype.list = this.list==null null:(List) ((ArrayList)this.list).clone(); cpBasePrototype.maps = (Map
) (this.maps == null null:((HashMap) this.maps).clone()); cpBasePrototype.concretePrototype = this.concretePrototype == null null:this.concretePrototype.clone(); return cpBasePrototype; } }
原型模式可以很好的copy对象而不用去new一个对象。对于复杂的数据类型资源上来讲其实是很方便的。
它的核心任务就是节省开支,方便操作返回一个同样的对象。还有好多的结识比如深度和浅度的问题。在上边的实例完全做了一个深度的clone操作。