강의

멘토링

로드맵

Inflearn Community Q&A

cupjoo1120's profile image
cupjoo1120

asked

Real-world! Spring Boot and JPA Utilization 1 - Web Application Development

Order and OrderItem Entity Development

생성자에 static 제어자를 쓰는 이유가 있나요?

Written on

·

421

4

public static OrderItem createOrderItem(...){

// ...

}

1. 제목과 동일합니다.  저 같은 경우엔 @Builder를 사용하긴 하는데 빌더패턴보다 더 선호되는 방식인가요?

2. 또한 생성자명을 따로 정하는 이유가 있을까요? 뭔가 의도는 알 거 같기도 한데, 제 추측 말고 정확한 이유가 궁금합니다.

웹앱JPAjavaspring-bootspring

Quiz

What is the main business logic that occurs when an order is cancelled?

Order status changes to 'Shipping'.

Stock of ordered items is decreasing.

Stock of canceled order items is restored.

Even delivered orders can be freely cancelled.

Answer 2

4

yh님의 프로필 이미지
yh
Instructor

안녕하세요. Junyoung_Choi님

정적 팩토리 메소드라고 합니다. 이 단어로 검색해 보시면 원하는 답을 얻을 수 있습니다^^

감사합니다.

1

정적 팩토리 메소드 사용 이유중에 static 메모리에 올라가기때문에 새로운 객체를 생성하지 않는 장점이 있는 거라고 알고 있습니다. 이 예제의 경우 static을 빼도 JPA가 엔티티로 관리하면서 어차피 사용할 수 있는 부분아닌가요..? 기본 생성자만 DB에서 값을 가져올 때 사용되는건가요?

yh님의 프로필 이미지
yh
Instructor

안녕하세요. 탈룰라님 static을 빼보시면 이해가 되실꺼에요.

질문이 오래되어서 혹시 추가 질문이 있으면 새로 질문을 정리해서 남겨주세요^^

감사합니다.

cupjoo1120's profile image
cupjoo1120

asked

Ask a question