Builder Pattern with Project Lombok
Normally, when we need to create an object with a lot of its information, we can use the Builder Pattern for that purpose. For example, I have a Student class as below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
package com.huongdanjava.lombok; public class Student { private String firstName; private String middleName; private String lastName; private String country; public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getMiddleName() { return middleName; } public void setMiddleName(String middleName) { this.middleName = middleName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getCountry() { return country; } public void setCountry(String country) { this.country = country; } @Override public String toString() { return "Student{" + "firstName='" + firstName + '\'' + ", middleName='" + middleName + '\'' + ", lastName='" + lastName + '\'' + ", country='" + country + '\'' + '}'; } } |
To build this object with all information using the Builder Pattern, we… Read More