BUILDER Flashcards
Builder is
a creational design pattern that lets you construct
complex objects step by step. The pattern allows you to produce different types and representations of an object using
the same construction code.
The Builder interface declares
product construction steps that
are common to all types ofbuilders.
Concrete Builders provide
different implementations of the
construction steps. Concrete builders may produce products
that don’t follow the common interface.
Products are
resulting objects. Products constructed by different builders don’t have to belong to the same class hierarchy
or interface.
The Director class defines
the order in which to call construction steps, so you can create and reuse specific configurations
of products.
What must the client associate with the director?
The client must associate one of the builder objects with the director
How is the builder usually associated with the director?
It’s usually done once, via the parameters of the director’s constructor.
What does the director do after associating the builder?
The director uses that builder object for all further construction.
Is there an alternative approach for associating the builder with the director?
Yes, the client can pass the builder object to the production method of the director.
What is the benefit of passing a builder object to the director’s production method?
In this case, you can use a different builder each time you produce something with the director.
What problem does the Builder pattern solve in constructors?
It helps avoid a “telescopic constructor” where constructors with many optional parameters are overloaded.
What is a telescopic constructor?
It is a constructor with many optional parameters, often overloaded to provide shorter versions with fewer parameters.
What does the Builder pattern allow developers to do?
It allows developers to build objects step by step, using only the steps they need, without cramming dozens of parameters into constructors.
When is the Builder pattern useful?
It’s useful when you need to create different representations of a product that involve similar steps, differing only in the details.
What does the base builder interface define?
The base builder interface defines all possible construction steps.