设计模式-单列模式

恶汉模式

public class DL{

  public static DL dl = new DL();

  private DL(){

  }

  public static DL getIntance(){

    return dl;

  }

}

懒汉模式

public class DL{

  public static DL dl;

  private DL(){

  }

  public synchronized  static DL getIntance(){

  

   if(dl==null){

    dl = new DL();

   }

   return dl;

  }

}

 

内部类单例模式

 

public class DL{

  private DL(){}

  static class DLHolder{

    static DL dl = new DL():

  }

  private static DL getIntance(){

    return DLHolder.dl;

  }

}

posted @ 2013-09-25 11:04  大川祥子  阅读(344)  评论(0编辑  收藏  举报