[url=http:/civis/viewtopic.php?p=25785119#p25785119:1we5xbq9 said:Bagheera[/url]":1we5xbq9]
Further research pointed me toward "Singletons", which ensure that only one instance of a class is instantiated. I can see a scenario where you'd want that. The getInstance() method checks to see if an object of that class already exists in the program. It returns null if an object exists. Couldn't you build that logic into the constructor?
Assuming you're talking about Java or C#, no, you can't build that logic into the constructor, because they don't have explicit return values.
Code:
public class Foo {
public Foo() {
// do stuff
}
}
...
Foo f = new Foo(); // A new instance of Foo is returned to the caller - every time - no matter what you do inside the constructor