benefit of 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
5:03 UTC
Read the original article
Hit count: 167
design-patterns
|php
I'm trying to understand the factory design pattern.
I don't 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