Abstract Factory, Factory Method, Builder

后端 未结 6 1137
清歌不尽
清歌不尽 2021-01-30 09:21

It may seem as if this is question is a dupe, but please bear with me - I promise I\'ve read the related posts (and the GOF book).

After everything I\'ve read, I still

6条回答
  •  既然无缘
    2021-01-30 09:43

    The Abstract Factory pattern uses subclassing (of factories) to produce other objects (non-factories). Abstract Factory also envisions that the objects produced belong to parallel hierarchies (e.g. to handle platform independance, one hierarchy for each platform).

    The Builder pattern uses subclassing to produce "output" - which is not necessarily objects at all. The GOF example has the Builder producing text output (markup or otherwise).

    The Factory Method pattern, unlike the other two, divides the "creator" into an abstract and concrete implementation (thus the emphasis on it belonging to a framework implementation). Like Abstract Factory, it deals with making actual objects.

    All three are highly similar, because they all use subclassing. It is the subclassing that is the outstanding quality of them all, which hides the subtle differences (outlined above) and thus many people have difficulty seeing the differences.

提交回复
热议问题