java原型(Protype)设计模式
2018-03-18 16:10
295 查看
原型模式就是讲一个对象作为原型,使用clone()方法来创建新的实例。
public class Prototype implements Cloneable{
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
protected Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}finally {
return null;
}
}
public static void main ( String[] args){
Prototype pro = new Prototype();
Prototype pro1 = (Prototype)pro.clone();
public class Prototype implements Cloneable{
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
protected Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}finally {
return null;
}
}
public static void main ( String[] args){
Prototype pro = new Prototype();
Prototype pro1 = (Prototype)pro.clone();
} }
相关文章推荐
- Java设计模式-5-原型模式
- java设计模式(工厂方法模式、抽象工厂模式、单例模式、建造者模式、原型模式、适配器模式、装饰器模式、代理模式、外观模式、桥接模式、组合模式、享元模式,。 行为型模式,共十一种:策略模式、模板方法)
- 设计模式之原型学习 java中的浅复制和深复制
- java软件体系设计模式----原型
- java学习笔记-设计模式6(原型模式)
- JAVA设计模式(原型模式)
- Java设计模式--原型模式
- java设计模式,原型模式
- JAVA设计模式七之 原型模式
- java/android 设计模式学习笔记(11)---原型模式
- 【创建型模式】原型模式(Prototype)之23种java设计模式
- JAVA系列-设计模式-原型模式
- java设计模式——创建型之原型模式
- JAVA--原型模式(Prototype)--设计模式五
- Java设计模式之六(原型模式)
- Java设计模式——创建型模式——原型模式(Prototype Pattern)
- java设计模式--创建模式--原型模式
- java设计模式之原型模式,如何实现深克隆
- java设计模式之原型模式
- java设计模式_原型模式