• 图解设计模式


    http://www.cnblogs.com/maowang1991/archive/2013/04/15/3023236.html

    http://download.csdn.net/detail/zhangerqing/4835830

    一、创建型:

      (Factory)工厂:

      

       (Builder)建造者:

      

    public static <T extends BaseRQ> T creat(Class<T> cls) {
            try {
                T rq = cls.newInstance();
                TmeUserAcc user = SecurityUserHolder.getCurrentUser();
                rq.setAppBrh(user.getBrhId());
                rq.setLoginName(user.getUserAccId());
                rq.setAppNo(BaseRQ.PC);
                rq.setTimeStamp(DateUtil.getCurrDateTime());
                return rq;
            } catch (Exception e) {
                log.error("创建RQ异常",e);
            }
            return null;
        }

       (Singleton) 单例:http://www.cnblogs.com/shoubianxingchen/p/5748645.html

        

    public class PropertiesUtil {
        
        private static class Inner {
            static{
                prop = fillProperty("/global.properties");
            }
            private static Properties prop;
        }
    
        private static Logger log = LoggerFactory.getLogger(PropertiesUtil.class);
    
        public static Properties fillProperty(String propName) {
            InputStream in = null;
            try {
                in = PropertiesUtil.class.getResourceAsStream(propName);
                Properties prop = new Properties();
                prop.load(in);
                return prop;
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (null != in)
                    try {
                        in.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
            }
            return null;
        }
    
        public static String getProperty(String key) {
            if (null != Inner.prop) {
                return Inner.prop.getProperty(key);
            }
            log.debug(" init prop failed.");
            return null;
        }
    
        public static String getProperty(String fileName, String key) {
            if (null != fileName && fileName.trim().length() != 0) {
                Properties prop = fillProperty(fileName);
                if (null != prop) {
                    return prop.getProperty(key);
                }
                log.debug("can not find the file:" + fileName);
            }
            return null;
        }
        
        public synchronized static void fresh() {
            Inner.prop=PropertiesUtil.fillProperty("/global.properties");
        }
    
    }
    View Code

      (Prototype)原型模式:(Copy)

    public Object clone() throws CloneNotSupportedException {  
            Prototype proto = (Prototype) super.clone();  
            return proto;  
        }  
      
        /* 深复制 */  
        public Object deepClone() throws IOException, ClassNotFoundException {  
      
            /* 写入当前对象的二进制流 */  
            ByteArrayOutputStream bos = new ByteArrayOutputStream();  
            ObjectOutputStream oos = new ObjectOutputStream(bos);  
            oos.writeObject(this);  
      
            /* 读出二进制流产生的新对象 */  
            ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());  
            ObjectInputStream ois = new ObjectInputStream(bis);  
            return ois.readObject();  
        }  

      

    二、结构型:

      

    (Adapter):适配器模式:类适配、实例适配、接口适配。

    (Decorator、Bridge、Proxy):装饰器、桥接、代理

      注意比较装饰器和代理:装饰可以选择被装饰的对象,而代理则不能。

     (Facade、Composite、Flyweight):外观、组合、享元

     三、行为型

            

      (Strategy、Template Method

        

      (Observer、Iterator、Responsibility Chain、Command)观察者、迭代器、责任链、命令

        

      

      

       

      

       

      (Visitor、Mediator、Interpreter):访问者、中介者、解释器

  • 相关阅读:
    day103 跨域请求 与频率访问限制.
    day 102 GIT 的使用方法.
    day 101 天
    day 100天 VUE 父子传值,单页面.
    JS 在元素后插入元素
    JS 网页加载后执行多个函数
    MySQL 一般操作语句
    PHP 通过设置表单元素name属性生成数组
    PHP SQL语气中value必须添加单引号
    PHP 单引号和双引号的区别
  • 原文地址:https://www.cnblogs.com/shoubianxingchen/p/6699633.html
Copyright © 2020-2023  润新知