dimanche 9 juin 2019

In Builder pattern, what kinds of `Product`s can share the same `Builder` and the same `Director`?

Design Patterns, by Gamma et al, describes Builder pattern:

Intent

Separate the construction of a complex object from its representation so that the same construction process can create different representations

Motivation

enter image description here

Structure

enter image description here

Implementation

Why no abstract class for products? In the common case, the products produced by the concrete builders differ so greatly in their representation that there is little to gain from giving different products a common parent class. In the RTF example, the ASCIIText and the TextWidget objects are unlikely to have a common interface, nor do they need one. Because the client usually configures the director with the proper concrete builder, the client is in a position to know which concrete subclass of Builder is in use and can handle its products accordingly.

Is there some condition on what kinds of Products (e.g. ASCIItext, TexText, and TextWidget in Motivation example) can share the same Builder base class and the same Director?

Aucun commentaire:

Enregistrer un commentaire