原型模式

2018-03-06  本文已影响1人  863cda997e42

定义:用原型实例制定创建对象的种类,并且通过拷贝这些原型创建新的对象。

实现一个接口,然后重写clone方法。

public class PrototypeClass implements Cloneable{
    public PrototypeClass clone(){
        PrototypeClass prototypeClass = null;
        
        try{
            prototypeClass = (PrototypeClass)super.clone();
        } catch(CloneNotSupportedException e){
            e.printStackTrace();
        }
        return prototypeClass;
    }
}
上一篇 下一篇

猜你喜欢

热点阅读