Design Pattern (Part 04) — Builder Design Pattern

Creating a subclass for every possible configuration of an object

When to use a Builder Pattern

● When building a composite structural object
● When the construction process must allow different representations for the object that’s constructed

Advantage of Builder Design Pattern

  1. Given better control over the construction process.
  2. Given a clear separation between the construction and representation of an object.
  1. Java Builder class should have a public constructor with all the required attributes as parameters.
  2. Java Builder class should have methods to set the optional parameters and it should return the same Builder object after setting the optional attribute.
  3. The final step is to provide a build() method in the builder class that will return the Object needed by the client program. For this, we need to have a private constructor in the Class with Builder class as an argument.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store