added singleton sample

This commit is contained in:
Ilkka Seppala 2014-08-11 21:43:08 +03:00
parent 01bdcdc1ed
commit 72415386fe
4 changed files with 51 additions and 0 deletions

View File

@ -22,5 +22,6 @@
<module>builder</module>
<module>factory-method</module>
<module>prototype</module>
<module>singleton</module>
</modules>
</project>

23
singleton/pom.xml Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.iluwatar</groupId>
<artifactId>singleton</artifactId>
<version>1.0-SNAPSHOT</version>
<name>singleton</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,14 @@
package com.iluwatar;
public class App
{
public static void main( String[] args )
{
IvoryTower ivoryTower1 = IvoryTower.getInstance();
IvoryTower ivoryTower2 = IvoryTower.getInstance();
System.out.println("ivoryTower1=" + ivoryTower1);
System.out.println("ivoryTower2=" + ivoryTower2);
}
}

View File

@ -0,0 +1,13 @@
package com.iluwatar;
public class IvoryTower {
private static IvoryTower instance = new IvoryTower();
private IvoryTower() {
}
public static IvoryTower getInstance() {
return instance;
}
}