File tree Expand file tree Collapse file tree
pattern/src/com/premaseem Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99public class Client {
1010 public static void main (String [] args ) {
1111 System .out .println ("Singleton cook example " );
12- Cook cook1 = new Cook ();
13- Cook cook2 = new Cook ();
14- Cook cook3 = new Cook ();
12+ Cook cook1 = Cook . getInstance ();
13+ Cook cook2 = Cook . getInstance ();
14+ Cook cook3 = Cook . getInstance ();
1515
1616 cook1 .makeBroth ();
1717 cook2 .makeBroth ();
Original file line number Diff line number Diff line change 88*/
99public class Cook {
1010
11- public Cook (){
11+ private Cook (){
1212
1313 }
1414
15+ private static Cook uniqueInstance = null ;
16+
17+ public static Cook getInstance (){
18+
19+ if (uniqueInstance == null ){
20+ uniqueInstance = new Cook ();
21+ }
22+ return uniqueInstance ;
23+ }
1524 boolean saltAdded = false ;
1625
1726 public void makeBroth (){
You can’t perform that action at this time.
0 commit comments