티스토리 뷰

@Builder

Builder는 오브젝트 생성을 위한 디자인 패턴

롬복이 제공하는 해당 어노테이션을 사용하면 Builder 클래스를 따로 개발하지 않고 Builder 패턴 사용해 오브젝트 생성

이렇게 빌더 패턴을 사용하는 것은 생성자를 이용해 오브젝트를 생성하는 것과 비슷하다.

생성자를 이용하는 것과 비교해 장점이 있다면 생성자 매개변수의 순서를 기억할 필요가 없다는 점.

 

EXAMPLE CODE

Car sonata = Car.builder()
            .id("가2056나")
            .userId("강백호")
            .title("ef sonata")
            .build();

@NoArgsConstructor

매개변수가 없는 생성자를 구현

EXAMPLE CODE

public Car() {

}

@AllArgsConstructor

클래스의 모든 멤버 변수를 매개변수로 받는 생성자를 구현

EXAMPLE CODE

public Car(String id, String userId, String title){
    super();
    this.id = id;
    this. userId = userId;
    this.title = titel;
}

@Data

클래스 멤버 변수의 Getter/Setter 메서드를 구현

public String getId(){
	return id;
}
public void setId(String id){
	this.id = id;
}
public String getuserId(){
	return userId;
}
public void setUserId(String userId){
	this.userId = userId;
}
public String getTitle(){
	return title;
}
public void setTitle(String title){
	this.title = title;
}
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/11   »
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
글 보관함