BUILDER Flashcards

1
Q

Builder is

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The Builder interface declares

A

product construction steps that
are common to all types ofbuilders.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Concrete Builders provide

A

different implementations of the
construction steps. Concrete builders may produce products
that don’t follow the common interface.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Products are

A

resulting objects. Products constructed by different builders don’t have to belong to the same class hierarchy
or interface.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The Director class defines

A

the order in which to call construction steps, so you can create and reuse specific configurations
of products.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What must the client associate with the director?

A

The client must associate one of the builder objects with the director

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How is the builder usually associated with the director?

A

It’s usually done once, via the parameters of the director’s constructor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the director do after associating the builder?

A

The director uses that builder object for all further construction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Is there an alternative approach for associating the builder with the director?

A

Yes, the client can pass the builder object to the production method of the director.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the benefit of passing a builder object to the director’s production method?

A

In this case, you can use a different builder each time you produce something with the director.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What problem does the Builder pattern solve in constructors?

A

It helps avoid a “telescopic constructor” where constructors with many optional parameters are overloaded.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a telescopic constructor?

A

It is a constructor with many optional parameters, often overloaded to provide shorter versions with fewer parameters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the Builder pattern allow developers to do?

A

It allows developers to build objects step by step, using only the steps they need, without cramming dozens of parameters into constructors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When is the Builder pattern useful?

A

It’s useful when you need to create different representations of a product that involve similar steps, differing only in the details.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the base builder interface define?

A

The base builder interface defines all possible construction steps.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What do concrete builders do?

A

Concrete builders implement the construction steps to build specific representations of the product.

17
Q

What role does the director class play in the Builder pattern?

A

The director class guides the order of construction and can use the same builder object in various ways to construct the product.

18
Q

What is the benefit of using the Builder pattern for complex objects?

A

It allows for constructing complex objects, such as composite trees, step by step, and you can defer or run some steps recursively.

19
Q

What is one important consideration when implementing the Builder pattern?

A

You need to ensure that the common construction steps for all product representations are clearly defined.

20
Q

What method do builders need to implement?

A

Builders need to implement a method for fetching the result of construction. This method may differ across builders depending on the product type.

21
Q

How does the Builder pattern relate to the Director class?

A

The director class can encapsulate various ways of constructing a product using the same builder object, and it can either pass the builder through the constructor or directly to the construction method.

22
Q

When should the client fetch the result of construction?

A

The client should fetch the result from the builder if the products don’t share a common interface; otherwise, the result can be fetched from the director.

23
Q

What are the main advantages of using the Builder pattern?

A

It allows step-by-step construction, deferring steps, running steps recursively, reusing construction code for different product representations, and isolating complex construction logic from business logic.

24
Q

What is the downside of using the Builder pattern?

A

The overall complexity of the code increases due to the need for creating multiple new classes.

25
Q

How does Builder relate to other design patterns?

A

Builder can evolve from Factory Method and can be combined with Abstract Factory, Prototype, and Bridge. It focuses on building complex objects step by step, while Abstract Factory focuses on creating families of related objects.

26
Q

Can Builder be used with Singleton?

A

Yes, Abstract Factories, Builders, and Prototypes can all be implemented as Singletons.