Skip to content

Commit

Permalink
example of singleton pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
rvasikarla committed Apr 5, 2015
1 parent f7d9084 commit 1e8ec50
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
@@ -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);

}
}
@@ -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);
}
}

0 comments on commit 1e8ec50

Please sign in to comment.