|
@@ -1,6 +1,7 @@
|
|
|
package cn.qinys.learn;
|
|
package cn.qinys.learn;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+import cn.qinys.learn.creational.singleton.Singleton;
|
|
|
import org.springframework.boot.SpringApplication;
|
|
import org.springframework.boot.SpringApplication;
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
|
|
|
@@ -9,5 +10,15 @@ public class PatternApplication {
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
|
SpringApplication.run(PatternApplication.class, args);
|
|
SpringApplication.run(PatternApplication.class, args);
|
|
|
|
|
+
|
|
|
|
|
+ // Demonstrate Singleton pattern
|
|
|
|
|
+ Singleton singleton1 = Singleton.getInstance();
|
|
|
|
|
+ Singleton singleton2 = Singleton.getInstance();
|
|
|
|
|
+
|
|
|
|
|
+ // Check if both references point to the same instance
|
|
|
|
|
+ System.out.println("Are both instances the same? " + (singleton1 == singleton2));
|
|
|
|
|
+
|
|
|
|
|
+ // Call a method on the singleton
|
|
|
|
|
+ singleton1.showMessage();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|