Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In which cases it makes sense to use factory classes instead of static functions?

Currently I have created a ABCFactory class that has a single method creating ABC objects. Now that I think of it, maybe instead of having a factory, I could just make a static method in my ABC Method. What are the pro's and con's on making this change? Will it not lead to the same? I don't foresee having other classes inherit ABC, but one never knows!

Thanks

like image 310
devoured elysium Avatar asked Apr 01 '10 21:04

devoured elysium


1 Answers

Having a single, static method makes this much more difficult to test whereas having an instantiable object allows this to be easier to test. Also, dependency injection is later more of an option with the non-static solution.

Of course, if you don't need any of this, then these are not good arguments.

like image 148
Jaxidian Avatar answered Sep 24 '22 20:09

Jaxidian