cs711_33
cs711_33
Software Design
Lecture : 33
2
Motivation Continue…
This approach is suitable as long as the object
under construction is simple and the object
construction process is definite and always
produces the same representation of the object.
5
Motivation
This design may not be effective when the object being
created is complex and the series of steps constituting the
object creation process can be implemented in different
ways producing different representations of the object.
Different implementations of the construction process are
all kept within the object, the object can become bulky
(construction bloat) and less modular. Subsequently,
adding a new implementation or making changes to an
existing implementation requires changes to the existing
code.
6
Builder Pattern
Using the Builder pattern, the process of constructing such
an object can be designed more effectively.
There can be more than one such builder class each with
different implementation for the series of steps to construct
the object.
8
Builder Pattern
Each such builder implementation results in a
different representation of the object.
Class Diagram
Sequence Diagram
12
builders.
16
Improvements in Previous
Design
The new design eliminates the need for a
client object to deal with the methods
constituting the object construction
process and encapsulates the details of
how the object is constructed from the
client.
17
Interaction Flow
i. The client object creates instances of an appropriate
concrete Builder implementer and the Director. The
client may use a factory for creating an appropriate
Builder object.
Sequence Diagram
21
Applicability
Comparison of Creational
Patterns
28