package com.example.demo.designPattern.builderMode.chain;
import lombok.Data;
/**
* @program: People
* @description:
* @author: liu wei ping
* @create: 2022-02-19 17:33
*/
@Data
public class Course {
private String name;
private String ppt;
private String video;
private String note;
private String homework;
@Override
public String toString() {
return "Course{" +
"name='" + name + '\'' +
", ppt='" + ppt + '\'' +
", video='" + video + '\'' +
", note='" + note + '\'' +
", homework='" + homework + '\'' +
'}';
}
}
package com.example.demo.designPattern.builderMode.chain;
/**
* @program: People
* @description:
* @author: liu wei ping
* @create: 2022-02-19 17:38
*/
public interface CourseBuilder {
Course Builder();
}
package com.example.demo.designPattern.builderMode.chain;
/**
* @program: People
* @description: 建造者模式 链式风格
* @author: liu wei ping
* @create: 2022-02-19 17:39
*/
public class CourseBuilderImpl implements CourseBuilder {
private Course course = new Course();
public CourseBuilderImpl addName(String name) {
course.setName(name);
return this;
}
public CourseBuilderImpl addPpt(String ppt) {
course.setPpt(ppt);
return this;
}
public CourseBuilderImpl addVideo(String video) {
course.setVideo(video);
return this;
}
public CourseBuilderImpl addNote(String note) {
course.setNote(note);
return this;
}
public CourseBuilderImpl addHomework(String homework) {
course.setHomework(homework);
return this;
}
@Override
public Course Builder() {
return course;
}
}
package com.example.demo.designPattern.builderMode.chain;
/**
* @program: People
* @description: 测试建造者模式
* @author: liu wei ping
* @create: 2022-02-19 17:45
*/
public class TestBuilder {
public static void main(String[] args) {
CourseBuilderImpl courseBuilder = new CourseBuilderImpl().addName("技术")
.addPpt("ppt").addVideo("video")
.addNote("note").addHomework("homework");
System.out.println(courseBuilder.Builder());
}
}