This is a type of creational design pattern where user can create object without specifying all the parameter of the constructor to build the object using a builder .
Advantage:
1.No need to specify all the parameter into constructor .
2.No need to maintain parameter sequence in constructor .
3.User can create object by their need .
Ex:
PC class:
public class PC {
private String ram;
private String processor;
private String hdd;
private String motherBoard;
public PC(String ram, String processor, String hdd, String motherBoard) {
super();
this.ram = ram;
this.processor = processor;
this.hdd = hdd;
this.motherBoard = motherBoard;
}
@Override
public String toString() {
return "PC [ram=" + ram + ", processor=" + processor + ", hdd=" + hdd + ", motherBoard=" + motherBoard + "]";
}
}
No comments:
Post a Comment