zoukankan      html  css  js  c++  java
  • 单例模式

    设计模式的意义在于:面向业务内容、业务数据结构和系统架构,高内聚低耦合、优雅的将平面逻辑立体化。

     1 package designPattern;
     2 /**
     3  * 单例模式
     4  */
     5 public class A1_SingletonTest {
     6 
     7     public static void main(String[] args) {
     8         Singleton s1 = Singleton.getInstance();
     9         Singleton s2 = Singleton.getInstance();
    10         if (s1 == s2) {
    11             System.out.println("单例模式!");
    12         }else {
    13             System.out.println("不是单例模式...");
    14         }
    15     }
    16 }
    17 
    18 class Singleton
    19 {
    20     private static Singleton s;;
    21     
    22     private Singleton() {}
    23 
    24     public static Singleton getInstance()
    25     {
    26         if (s==null) {
    27             s = new Singleton();
    28         }
    29         return s;
    30     }
    31 }

      

    环境:JDK1.6,MAVEN,tomcat,eclipse

    源码地址:http://files.cnblogs.com/files/xiluhua/designPattern.rar

    欢迎亲们评论指教。

  • 相关阅读:
    魔法跳舞链 51Nod
    反射
    JDBC---后端服务器与数据库交互的桥梁
    多线程
    IO流
    继承与重写
    java.util包
    多态
    Java.lang包
    异常
  • 原文地址:https://www.cnblogs.com/xiluhua/p/4412286.html
Copyright © 2011-2022 走看看