Builder Design Pattern

         Builder design patter is used to create an object with optional instance attributes.If you want some introduction about design patterns please refer here.

        So, first step is to know what wikipedia says about builder design pattern,
The intent of the Builder design pattern is to separate the construction of a complex object from its representation.
        Second Step is to find an real world example (behavior) of builder design pattern.

Builder pattern is similar to Buffet system, where diners will serve themselves (they pick what dishes they want) , here we need map each dish as instance attributes and people as the client class need to create a object with optional attributes.
       

        Now the fun part, below codes shows the implementation of builder pattern

        Here's the builder pattern used class,
      
        These builder pattern  are boilerplate code, you can use lombok's @Builder annotation above person class, which provides similar functionality of what above implemented.

       Thanks for reading the post, ciao until next time.




Comments

Popular posts from this blog

Avro Secondary Sorting

Git Bundle