Lecture 7-Builder pattern Flashcards

1
Q

What is the intent behind the builder pattern?

A

To separate the construction of a complex object from its representation, so that the same construction process can create different representations.

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

What are 2 situations where we would use the builder pattern ?

A

1.Algo of creating a complex object is independent of the parts that make uptime object and how they are assembled.
2. Construction process must allow different representations for the object that is constructed.

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

How can we use the builder pattern? (2)

A
  1. Use it to get rid of a telescopic constructor.–> overload the constructor and create several shorter versions with fewer parameters.
  2. Use it to construct Composite trees or other complex objects.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are some pros of the builder pattern(3)

A

-You can construct objects step-by-step, defer construction steps, or runt them recursively.
-You can reuse the same construction code when building representations.
-SRP( Single Responsibility Principle) : Can isolate complex construction code from business logic.

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

What is the con of the builder pattern?

A

The overall complexity of code increases since it requires creation of multiple new classes.

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