So almost every post I read about oop by purists, they keep stressing about how using static methods is anti pattern and breaks the testability of the code. On the other hand every time I look for some example code using factories (irrespective of programming language) specially for the purpose of object construction, I see a static method in the factory class returning the constructed object. (pseudo code below)
class ProductFactory() {
public static function make(string name): Product
{
if(name contains TV)
return new TVProduct(name)
else
return new HomeAppliance(name);
}
}
product = ProductFactory->make('LCD TV');
To me this looks perfectly fine because ultimately I want an instance of the object and not the instance of factory as will be the case below.
productFactory = new ProductFactory();
product = productFactory->make('LCD TV');
My question is two fold here.
1- What is the real way of using factories? is static method in a factory the proper & accepted way to use them?
2- How do we write unit tests for a factory that uses a static method ?
I hope my understanding of using factories for object construction is not flawed at fundamental level.

