2

I'm just studying the Builder pattern and do not understand the point of the Director.

http://en.wikipedia.org/wiki/Builder_pattern

Wouldn't just having Builder and their subclasses be sufficient?

Thanks

skaffman
  • 398,947
  • 96
  • 818
  • 769
TheWommies
  • 4,922
  • 11
  • 61
  • 79

1 Answers1

6

The Builder exposes methods for making alterations to the item being produced. The Director holds the knowledge of which of these methods, for a given use, should be called, and in what order.

The Builder could be reused for multiple purposes, and contains knowledge of the internals of the product. The Director is used for a specific purpose, and contains knowledge of what the product needs to have to be used in the intended domain.

Jacob Mattison
  • 50,258
  • 9
  • 107
  • 126
  • Can I Ask here? Let me try to understand this better: If the director know how to produce the object, as client, I should pass info to the director itself? At this point, it's not the same to give to directly to the concrete builder itself? – Tizianoreica Sep 06 '17 at 09:21
  • 1
    The object playing the role of Director may be the client itself, but if you have a situation where there are various builder types, or various builder methods that may only be called in certain situations, it may be a good idea to have an object that encapsulates the knowledge of which builder objects and methods should be used for what situation.That would be the Director. – Jacob Mattison Sep 06 '17 at 13:12