Skip to content

Commit 7241538

Browse files
committed
added singleton sample
1 parent 01bdcdc commit 7241538

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
<module>builder</module>
2323
<module>factory-method</module>
2424
<module>prototype</module>
25+
<module>singleton</module>
2526
</modules>
2627
</project>

singleton/pom.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<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"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>com.iluwatar</groupId>
7+
<artifactId>java-design-patterns</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<groupId>com.iluwatar</groupId>
11+
<artifactId>singleton</artifactId>
12+
<version>1.0-SNAPSHOT</version>
13+
<name>singleton</name>
14+
<url>http://maven.apache.org</url>
15+
<dependencies>
16+
<dependency>
17+
<groupId>junit</groupId>
18+
<artifactId>junit</artifactId>
19+
<version>3.8.1</version>
20+
<scope>test</scope>
21+
</dependency>
22+
</dependencies>
23+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.iluwatar;
2+
3+
public class App
4+
{
5+
public static void main( String[] args )
6+
{
7+
8+
IvoryTower ivoryTower1 = IvoryTower.getInstance();
9+
IvoryTower ivoryTower2 = IvoryTower.getInstance();
10+
System.out.println("ivoryTower1=" + ivoryTower1);
11+
System.out.println("ivoryTower2=" + ivoryTower2);
12+
13+
}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.iluwatar;
2+
3+
public class IvoryTower {
4+
5+
private static IvoryTower instance = new IvoryTower();
6+
7+
private IvoryTower() {
8+
}
9+
10+
public static IvoryTower getInstance() {
11+
return instance;
12+
}
13+
}

0 commit comments

Comments
 (0)