Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rvasikarla
committed
Apr 5, 2015
1 parent
f7d9084
commit 1e8ec50
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/main/java/com/learnings/designpatterns/creational/singletonpattern/Consumer1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.learnings.designpatterns.creational.singletonpattern; | ||
|
||
public class Consumer1 { | ||
|
||
public static void main(String[] args) { | ||
|
||
Singleton single = new Singleton(); | ||
System.out.println(single.a); | ||
|
||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/learnings/designpatterns/creational/singletonpattern/Singleton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.learnings.designpatterns.creational.singletonpattern; | ||
|
||
public class Singleton { | ||
|
||
public static Singleton uniqueInstance; | ||
public static int a = 10; | ||
|
||
public static Singleton getInstance() { | ||
if (uniqueInstance == null) { | ||
uniqueInstance = new Singleton(); | ||
} | ||
return uniqueInstance; | ||
} | ||
|
||
public void sample(String name) { | ||
System.out.println("This is Sample : " + name); | ||
} | ||
} |