Professional Documents
Culture Documents
Day 4 - Builder, Prototype Design Patterns
Day 4 - Builder, Prototype Design Patterns
Day 4 - Builder, Prototype Design Patterns
Where is it used:
Key Components:
● Director: Responsible for orchestrating the construction process and delegates the construction steps
to the builder.
● Builder: Abstract interface or base class for creating parts of the complex object.
● ConcreteBuilder: Implements the builder interface and provides specific implementations for
constructing the parts and assembling the object.
● Product: Represents the complex object being constructed.
Advantages:
● Separation of Concerns: The Builder pattern separates the construction logic from the representation,
promoting a clean separation of concerns.
● Complex Object Creation: It simplifies the creation of complex objects with many optional parameters
by providing a step-by-step construction process.
Disadvantages:
● Code Overhead: Introducing a builder can lead to additional code and complexity, especially for
objects with only a few parameters.
● Complexity: For simple objects, using the Builder pattern can be overkill and make the code
unnecessarily complex.
● Increased Memory Usage: Builders can lead to increased memory usage, as they involve creating
multiple objects during construction.
Key Components:
a. Prototype: An abstract interface or base class that declares a method for cloning itself.
b. ConcretePrototype: Implements the prototype interface and provides a method for cloning itself.
c. Client: Initiates the cloning process by requesting the creation of new objects from prototypes.
Advantages:
● Reduced Object Creation Overhead: It eliminates the need to create objects from scratch, saving
time and resources.
● Dynamic Object Creation: Allows for the creation of new object instances with varying configurations
and data, making it suitable for scenarios where objects evolve.
● Simplifies Object Initialization: Objects can be created with a default state and customized as
needed, simplifying the initialization process.
Disadvantages:
● Cloning Complexity: Cloning objects may be complex, especially when dealing with deep copies of
objects with complex internal structures.
● Shallow Copy Limitations: By default, prototypes often perform shallow copies, which may not be
suitable for objects with complex or shared internal state.