myth about factory pattern

Posted by leiz on Stack Overflow See other posts from Stack Overflow or by leiz
Published on 2010-04-23T09:49:12Z Indexed on 2010/04/23 9:53 UTC
Read the original article Hit count: 401

Filed under:
|

This has bothered me for awhile, and I have no clues if this is a myth.

It seems that a factory pattern can ease the pain of adding a dependency for a class.

For example, in a book, it has something like this

Suppose that you have a class named Order. Initially it did not depend on anything. Therefore you didn't bother using a factory to create Order objects and you just used plain new to instantiate the objects. However, you now have a requirement that Order has to be created in association with a Customer. There are million places you need to change to add this extra parameter. If only you had de?ned a factory for the Order class, you would have met the new requirement without the same pain.

How is this not same pain as adding an extra parameter to the constructor? I mean you would still need to provide an extra argument for the factory and that is also used by million places, right?

© Stack Overflow or respective owner

Related posts about factory-pattern

Related posts about myths