@@ -0,0 +1,1448 @@
+package com.yxy.chukonu.java.dp.builder;%0A/**%0A * This class is for demonstrating how does Builder Pattern work%0A * @author xianyiye%0A *%0A */%0Apublic class Student %7B%0A%0A%09private String name;%0A%09private int age;%0A%09private String address;%0A%09private String ID;%0A%09%0A%09%0A%09private Student(Builder build) %7B%0A%09%09this.name = build.name;%0A%09%09this.age = build.age;%0A%09%09this.address = build.address;%0A%09%09this.ID = build.ID;%0A%09%7D%0A%0A%09public String getName() %7B%0A%09%09return this.name;%0A%09%7D%0A%0A%09public int getAge() %7B%0A%09%09return this.age;%0A%09%7D%0A%0A%09public String getAddress() %7B%0A%09%09return this.address;%0A%09%7D%0A%0A%09public String getID() %7B%0A%09%09return this.ID;%0A%09%7D%0A%0A%09public void method() %7B%0A%09%09System.out.println(name);%0A%09%7D%0A%0A%09/**%0A%09 * Builder class%0A%09 *%0A%09 */%0A%09static class Builder %7B%0A%0A%09%09private String name = null;%0A%09%09private int age = 0;%0A%09%09private String address = null;%0A%09%09private String ID = null;%0A%0A%09%09public Builder() %7B%0A%09%09%7D;%0A%0A%09%09public Builder(String name)%7B%0A%09%09%09this.name=name;%0A%09%09%7D%0A%0A%09%09public Builder setName(String name) %7B%0A%09%09%09this.name = name;%0A%09%09%09return this;%0A%09%09%7D%0A%0A%09%09public Builder setAge(int age) %7B%0A%09%09%09this.age = age;%0A%09%09%09return this;%0A%09%09%7D%0A%0A%09%09public Builder setAddress(String address) %7B%0A%09%09%09this.address = address;%0A%09%09%09return this;%0A%09%09%7D%0A%0A%09%09public Builder setID(String ID) %7B%0A%09%09%09this.ID = ID;%0A%09%09%09return this;%0A%09%09%7D%0A%0A%09%09public Student build()%7B%0A%09%09%09return new Student(this);%0A%09%09%7D%0A%0A%09%7D%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09%0A%09%09Student student = new Student.Builder().setName(%22zhangsan%22).setAge(12).setAddress(%22beijing%22).build();%0A%0A%09%7D%0A%0A%7D%0A

add example for Builder Pattern