Difference between Abstract factory and builder?

前端 未结 3 811
遇见更好的自我
遇见更好的自我 2021-02-10 18:22

Sorry for asking again. I have searched over web but couldn\'t understand hence i have to put here. Here what I research by my self. I studied from head first design pattern.

3条回答
  •  抹茶落季
    2021-02-10 19:22

    The Builder and Abstract Factory patterns are similar in that they both look at construction at an abstract level. However, the Builder pattern is concerned with how a single object is made up by the different factories, whereas the Abstract Factory pattern is concerned with what products are made. The Builder pattern abstracts the algorithm for construction by including the concept of a director. The director is responsible for itemizing the steps and calls on builders to fulfill them. Directors do not have to conform to an interface.

    Other example (than yours) may be creating products instead of the client explicitly declaring fields of type ProductA and ProductB, say, the Product object the builder returns is actually a list of parts, which can have different lengths and contents depending on the director that was in charge at its creation.

提交回复
热议问题