Java private constructor and getInstance() method. Why?

Status
You're currently viewing only andrewme's posts. Click here to go back to viewing the entire thread.
Not open for further replies.

andrewme

Senator
7,120
Subscriptor
[url=http:/civis/viewtopic.php?p=25785119#p25785119:3n4ddosj said:
Bagheera[/url]":3n4ddosj]
The getInstance() method checks to see if an object of that class already exists in the program. It returns null if an object exists.

Never seen it done that way - typically the singleton accessor returns (a reference / pointer to) the single instance to every requester. This means every requester in the process can easily access the instance without having to clutter up the code passing it around or resorting to global variables.
 
Status
You're currently viewing only andrewme's posts. Click here to go back to viewing the entire thread.
Not open for further replies.