PatternSingleton: Initial commit

This commit is contained in:
2022-05-07 23:54:49 +02:00
parent 0fe0a70258
commit 87e8cd1e09
4 changed files with 51 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PatternSingleton</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,9 @@
public class PatternSingleton {
public static void main(String[] args) {
//Get the only object available
Singleton object = Singleton.getInstance();
//show the message
object.showMessage();
}
}

View File

@@ -0,0 +1,19 @@
public class Singleton {
//create an object of SingleObject
private static Singleton instance = new Singleton();
//make the constructor private so that this class cannot be
//instantiated
private Singleton(){}
//Get the only object available
public static Singleton getInstance(){
return instance;
}
public void showMessage(){
System.out.println("There can be only One!");
}
}