...
Code Block |
---|
public class CourseunitDto implements Serializable { private String name; //setters and getters private CourseunitDto() {} public static class Builder { private CourseunitDto courseunitDto; Builder() { this.courseunitDto = new CourseunitDto(); } public Builder name(String name) { if (name == null) { throw new IllegalArgumentException("Course should have a name"); } this.courseunitDto.setName(name); return this; } public CourseunitDto build() { return this.courseunitDto; } } } |
Tällöin dto-olio voidaan rakentaa seuraavasti.
Code Block |
---|
new CourseunitDto.Builder.name("test").build(); |
...