Should I use the factory design pattern for every class?

Posted by Frog on Programmers See other posts from Programmers or by Frog
Published on 2012-11-25T13:26:38Z Indexed on 2012/11/25 23:22 UTC
Read the original article Hit count: 210

I've been writing a website in PHP. As the code becomes more complex, I keep finding problems that can be solved using the factory design pattern. For example: I've a got a class Page which has subclasses HTMLPage, XMLPage, etc. Depending on some input I need to return an object of either one of these classes. I use the factory design pattern to do this.

But as I encounter this problem in more classes, I keep having to change code which still initiates an object using its constructor. So now I'm wondering: is it a good idea to change all code so that it uses the factory design pattern? Or are there big drawbacks?

I'm currently in a position to change this, so your answers would be really helpful.

© Programmers or respective owner

Related posts about php

Related posts about design-patterns