问题
I know this question is asked many times but I just want to clear more on this. Can a builder pattern replace factory pattern.
Yes Builder pattern create and return a complex object step by step and this can be done in factory pattern also.
回答1:
They are both Creational patterns. So, not replace, just an alternative that's appropriate under some conditions. The nature of patterns is that they present solutions to common problems, it's quite reasonable that subtly different problems have different solutions.
All discussed here, maybe it's more interesting if you tell us what you didn't understand or agree with about the answers here
回答2:
For more information on when to use the Builder Pattern and its advantages you should check out my post for another similar question here
来源:https://stackoverflow.com/questions/1258638/does-the-builder-pattern-replace-the-factory-pattern