DEV Community

loading...

Builder pattern

Ravi Yasas
Software Engineer by profession. Author of https://javafoundation.xyz
・1 min read

This is another creational design pattern. Just think about the StringBuilder. If you create a StringBuilder object, you can append strings one by one to the same StringBuilder object.

    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("Java").append("Foundation");
Enter fullscreen mode Exit fullscreen mode

This is the functionality of the builder pattern. There are a few ways to implement the builder pattern.

Using constructor

Using inner classes

This is the best approach to implement the builder pattern.

--> Find advantages, disadvantages, usages and more details about the builder pattern

Discussion (2)

Collapse
andsmile profile image
Andrii

the most used way to implement builder nowadays is to use lombok Builder annotation
:)))

Collapse
raviyasas profile image
Ravi Yasas Author

Yeah. that is true.

Forem Open with the Forem app