Builder Design Pattern

What is the Builder Patter?
– The pattern used to create objects made from a bunch of other objects.
a. When you want to build an object made up from other objects
b. When you want the creation of these parts to be independent of the main object
c. Hide the creation of the parts from the client so both are not dependent
d. The builder knows the specifics and nobody else does

UML Digram:

Step 1: Create RobotBuilder interface

Step 2: Create OldRobotBuilder class which implements RobotBuilder

Step 3: Create RobotPlan interface

Step 4: Create Robot class which implements RobotPlan

Step 5: Create RobotEngineer class

Step 6: Create TestRobotBuilder class.
a. Create RobotBuilder object
b. Pass create robotbuilder object in RobotEngineer constructor.
c. With robotEngineer object call makeRobot

Output:

Robot built
Robot head: Ironman head
Robot Torso: Torso Ironman
Robot Arms: Powerful arms
Robot Legs: Flying legs

Please share your feedback at online.nimit@gmail.com, also comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *