原型模式(实现Cloneable接口,重写clone方法获取对象,如果有需要改变的属性值,就为其设置set方法)
package designMode;
import javax.lang.model.type.ReferenceType;
class RealizeType implements Cloneable{
public RealizeType() {
System.out.println("具体原型创建成功");
}
public Object clone() throws CloneNotSupportedException{
System.out.println("具体原型复制成功!");
return (RealizeType)super.clone();
}
}
public class Prototype {
public static void main(String[] args) throws CloneNotSupportedException {
// TODO Auto-generated method stub
RealizeType obj1=new RealizeType();
RealizeType obj2=(RealizeType)obj1.clone();
System.out.println("obj1==obj2?"+(obj1==obj2));
}
}