zoukankan      html  css  js  c++  java
  • 原型模式(Prototype)

    Intent

    使用原型实例指定要创建对象的类型,通过复制这个原型来创建新对象。

    Class Diagram

    Implementation

    public abstract class Prototype {
        abstract Prototype myClone();
    }
    public class ConcretePrototype extends Prototype {
    
        private String filed;
    
        public ConcretePrototype(String filed) {
            this.filed = filed;
        }
    
        @Override
        Prototype myClone() {
            return new ConcretePrototype(filed);
        }
    
        @Override
        public String toString() {
            return filed;
        }
    }
    public class Client {
        public static void main(String[] args) {
            Prototype prototype = new ConcretePrototype("abc");
            Prototype clone = prototype.myClone();
            System.out.println(clone.toString());
        }
    }
    abc

    JDK

    • java.lang.Object#clone()
  • 相关阅读:
    线程池
    多线程随笔
    注解随笔
    反射机制
    iO流
    FastDFS+docker建立分布式文件系统
    Java之Exception
    Java之String
    手写SpringMvc
    spring中一些常用注解的含义
  • 原文地址:https://www.cnblogs.com/AnXinliang/p/9955461.html
Copyright © 2011-2022 走看看