Skip to main content

Posts

Showing posts from April, 2017

Builder Design Pattern - Java

Builder Design Pattern - Java When the construction of the class contains a large number of argument then this Design Pattern is preferred. Builder Pattern, as the name suggest, it helps to reduce the complexity in Building Java Object. public class Person { private String firstname; private String lastname; private String address; private int age; private String city; private String state; public Person(String firstname, String lastname, String address, int age, String city, String state) { super(); this.firstname = firstname; this.lastname = lastname; this.address = address; this.age = age; this.city = city; this.state = state; } } In the above example, you can see, that the construction of the Person class has 6 arguments and few of them can be optional. So we can create a new PersonBuilder class which will help to create the Object of the Person class. public class PersonBuilder { private String firstname;