Y
yzzzzz
Hi,
In the Java librairies there are many classes that can be built either
by using the constructor method (Foo a = new Foo()) or by calling a
static getInstance() method (Foo a = Foo.getInstance()).
Usually both have arguments, and often both are overloaded.
I was wondering if these 2 ways of creating a new object are equivalent,
or why and when I should use one way or the other. I usually overload my
constructors a lot, but it may be simpler to do a getInstance() method
instead. What are the advantages of each way?
Thanks.
In the Java librairies there are many classes that can be built either
by using the constructor method (Foo a = new Foo()) or by calling a
static getInstance() method (Foo a = Foo.getInstance()).
Usually both have arguments, and often both are overloaded.
I was wondering if these 2 ways of creating a new object are equivalent,
or why and when I should use one way or the other. I usually overload my
constructors a lot, but it may be simpler to do a getInstance() method
instead. What are the advantages of each way?
Thanks.