Lecture 7-Builder pattern Flashcards
What is the intent behind the builder pattern?
To separate the construction of a complex object from its representation, so that the same construction process can create different representations.
What are 2 situations where we would use the builder pattern ?
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 can we use the builder pattern? (2)
- Use it to get rid of a telescopic constructor.–> overload the constructor and create several shorter versions with fewer parameters.
- Use it to construct Composite trees or other complex objects.
What are some pros of the builder pattern(3)
-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.
What is the con of the builder pattern?
The overall complexity of code increases since it requires creation of multiple new classes.