如果单从static 方法与单例模式上做区分,他们应算没有什么区别 只不过单列模式要多敲几个XXXInstance字符罢了。

解决方案 »

  1.   

    单例模式的好处仅仅是"延迟加载",而不是初始化的时候就加载
    而且即使是单例模式,也有把私有属性设置成static的方式
    而且函数本来就不需要做成实例的,除非函数里还要用到非静态的属性
      

  2.   


    private ProductBLL productBll;
    private ProductBll PorductBllInstance{  
    get{
      if( this.productBll==null ){  this.productBll=new ProductBll(); }
      return this.productBll;
    }
      }而且这种写法根本不是单例
    因为每实例化一次,productBll都是不同的对象,它绝对是null,这样写没有任何意义的
      

  3.   

    这样写法不是单例的问题,是全局访问,因为有很多人喜欢一种写法
    不管用不用,在字段部分直接先实例化,有时候你就会发现类顶部new了十几个bll,但你要用的方法其实根本用不到这些
    private ProductBLL productBll = new ProductBll(); 
    而这种写法其实就相当于Lazy<T>但就个人而言,不喜欢这种写法,个人一直喜欢在用的地方才实例
      

  4.   

    单例模式延迟加载:
    static private ProductBLL productBll;
    private ProductBll PorductBllInstance{  
    get{
      if( this.productBll==null ){  this.productBll=new ProductBll(); }
      return this.productBll;
    }
      }
    单例模式初始加载:private ProductBLL productBll=new ProductBll();
    private ProductBll PorductBllInstance{  
    get{
      return this.productBll;
    }
      }
      

  5.   

    晕死,错了
    单例模式初始化加载:
    static private ProductBLL productBll=new ProductBll();
    private ProductBll PorductBllInstance{  
    get{
      return this.productBll;
    }
      }
    如果不静态,就根本不可能是单例