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