Reputation: 32331
public class Factoryclass
{
public static MyClass returnObject(String str)
{
// Based on the parameter passed it will retrn some class
}
}
If in a Web Application , theer were 100 requests .
Now please tell me how many objects of Factoryclass will be created ??
Upvotes: 0
Views: 60
Reputation: 13755
if you do
Factoryclass.returnObject()
no Factoryclass
instances will be created, unless you do new Factoryclass()
inside the returnObject
method
Upvotes: 4
Reputation: 5780
It entirely depends on the content of your method returnObject(). The fact that it's a static method only means that it is "stateless" and doesn't pull from non-static instance members in order to work. However, you could potentially instantiate a new instance with each and every time it has been called.
The fact that it's a factory leads me to think that is, in fact, the case. However, the nature of the factory pattern would suggest that it should not matter to you whatsoever. If your implementation depends on the fact that this Factoryclass returns multiple instances or the same instance, someone made a wrong decision in making it a factory.
Upvotes: 0