group-icon
Java Developers
Group for Java developers and programmers. Ask questions and get answers related to Java programming
254 Members
Join this group to post and comment.
Soubhik Maji
Soubhik Maji
Computer Science
30 Jan 2019

Design Patterns : Singleton Design Pattern

"Instead of code reuse with patters you get experience reuse" 


Top design patterns to know-

1.observer

2.factory 

3.proxy

4.template

5.strategy


The following is taken from mobile.developers.com ...


Benefits of Design Patterns


"Design patterns have two major benefits. First, they provide you with a way to solve issues related to software development using a proven solution. The solution facilitates the development of highly cohesive modules with minimal coupling. They isolate the variability that may exist in the system requirements, making the overall system easier to understand and maintain. Second, design patterns make communication between designers more efficient. Software professionals can immediately picture the high-level design in their heads when they refer the name of the pattern used to solve a particular issue when discussing system design."


-James Maioriello, Ph.D., is a Senior Design Engineer for Formation Systems Inc. 





      Singleton design pattern -


1.Singleton pattern ensures that only one object/instance  of a class is created .  


2.How do we achieve this ..by making the constructor of the class private and having a get instance method


3.The get instance method checks whether a instance already exists by checking a static variable which contains the address of the instance if it exists 


4.If it already exists it simply returns that same address .


5.If it is null (static variable meant for storing reference to our instance of singleton class ) then we create a instance and set that to that variable  and also return that instance to the caller .


6.For someone to call get instance method without creating object will call for making it a static method , so this method is static of singleton class that creates the single instance of the singleton class .