单例模式简介

来源:互联网 发布:ubuntu不登录进入终端 编辑:程序博客网 时间:2024/05/17 02:51

   //单例模式的要点有三个;一是某个类只能有一个实例;二是它必须自行创建这个实例;三是它必须自行向整个系统提供这个实例。

private static ProductMgr pm = null;
    
    static {
        if (pm == null ){
            pm = new ProductMgr();
            pm.setDAO(new ProductMySQLDAO());
        }
    }
    
    public static ProductMgr getInstance(){
        return pm;
    }

0 0
原创粉丝点击