benefit os having a factory for object creation?

Posted by ajsie on Stack Overflow See other posts from Stack Overflow or by ajsie
Published on 2010-04-24T04:50:35Z Indexed on 2010/04/24 4:53 UTC
Read the original article Hit count: 187

Filed under:
|

im trying to understand the factory design pattern.

i dont understand why it's good to have a middleman between the client and the product (object that the client wants).

example with no factory:

$mac = new Mac();

example with a factory:

$appleStore = new AppleStore();
$mac = $appleStore->getProduct('mac');

how does the factory pattern decouple the client from the product?

could someone give an example of a future code change that will impact on example 1 negative, but positive in example 2 so i understand the importance of decoupling?

thanks

© Stack Overflow or respective owner

Related posts about design-patterns

Related posts about php