My program instantiates an object with parameters passed in command line. I need to be able to instantiate an object with those parameters but yet it should be created only once. I've read these posts 1 & 2 but I still didn't understand which approach is better:
1 - var myInstance = MyClass.Instance.Create("param1", "param2");
OR
2 - var myInstance = MyClass.Instance;
myInstance.setParam1("param1");
myInstance.setParam2("param2");
In the first approach the new instance for each different pair of parameters passed to Create will be created. The only way to prevent this is to set flag inside Create that will return the created instance.
In 2nd approach the problem is what if constructor of MyClass will depend on param1 and param2?
So, what would you suggest?