Builder Design Pattern (UML Class Diagram)

Builder pattern simplifies the creation of complex objects and unifies the creation process for different types of objects. The products created by a concrete builder may be subclasses of different product classes.

Builder Pattern in UML Class Diagram

The structure of Builder pattern is depicted using a UML Class Diagram. It shows the particular roles of the pattern using the class elements and the relationship between them using UML associations:

  • Director
  • Builder
  • Concrete Builder 1 and 2
  • Client
  • Product 1 and 2
Builder Design Pattern (UML Class Diagram)
Builder Design Pattern (UML Class Diagram)

Comments

Anonymous 29 October 2024 4:46:39

SDA

class Car {

private String color;

private String engineType;

private String transmission;

// Private constructor

private Car(CarBuilder builder) {

this.color = builder.color;

this.engineType = builder.engineType;

this.transmission = builder.transmission;

}

public static class CarBuilder {

private String color;

private String engineType;

private String transmission;

public CarBuilder setColor(String color) {

this.color = color;

return this;

}

public CarBuilder setEngineType(String engineType) {

this.engineType = engineType;

return this;

}

public CarBuilder setTransmission(String transmission) {

this.transmission = transmission;

return this;

}

public Car build() {

return new Car(this);

}

}

}

// Usage:

Car car = new Car.CarBuilder()

.setColor("Red")

.setEngineType("V8")

.setTransmission("Automatic")

.build();

New Comment

Comment