Hi all, in singleton design pattern. We normally have a method call getInstance() which takes in no argument. I'm wondering is it ok to pass in a parameter, for eg. java.sql.Connection to retrieve record from the database?
You can do anything you want, but the normal purpose of the getInstance() method in a singleton class is to return an instance of the class. You then use that instance to call other methods of the class to do whatever processing you want.
However, although a bit unusual for Singletons, you could use it to return a single instance for each different parameter value. So each connection can have only one instance.
Keep in mind though that at some time you want to clean up or your singleton's cache could keep increasing until you get a memory error.