Java 之原型模式

public interface Prototype {
    
   public Object cloneObject();
}


public class ConcretePrototype implements Prototype {

    @Override
    public Object cloneObject() {
        // TODO Auto-generated method stub
        return new ConcretePrototype();
    }
}

public class Client {
    
    private Prototype prototype;
    
    public Client(Prototype prototype) {
        this.prototype = prototype;
    }
    
    public Prototype getPrototype() {
        return prototype;
    }



    public void setPrototype(Prototype prototype) {
        this.prototype = prototype;
    }

    public static void main(String[] args) {
        Client c = new Client(new ConcretePrototype());
        c.getPrototype().cloneObject();
    }
}

學習設計模式強烈推薦的博客:java_my_lifejava

代碼地址:lennongit

相關文章
相關標籤/搜索