Skip to main content

Posts

Showing posts from 2016

The builder pattern in Java 8

The builder pattern is an alternative to construct complex object. This can be used only when you want to build different immutable object in the same building process. It allows object creation using method chaining and more flexible object creation. Example: Let's take Person as data model package com.javaweblog.build.pattern; public class Person { private String firstName; private String lasteName; private int age; private String gender; public Person(String firstName, String lasteName, int age, String gender){ this.firstName = firstName; this.lasteName = lasteName; this.age = age; this.gender = gender; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLasteName() { return lasteName; } public void setLasteName(String lasteName) { this.lasteName = lasteName; } public int getAge() { return age; } public void setAge(int age) { th...