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

相关文章
相关标签/搜索