-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[refactor] 약속 추가 플로우 데이터 전달 간소화 #400
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
빌더 패턴은 처음 알았는데 객체 생성 시에 간편하게 활용해볼 수 있겠네요! 저도 약속 수정이나 약속 상세 뷰모델 생성자로 많은 객체를 넘기는 게 힘들었는데 빌더 패턴 도입해보면 좋을 것 같습니다.
고생하셨습니다 🔥
private var y = 0.0 | ||
private var participants = [Int]() | ||
|
||
@discardableResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@discardableResult
는 왜 사용하신건지 궁금해요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
방금 막 아요 코드리뷰하면서 @discardableResult
보고 똑같이 리뷰 남겼는데 여기 또 있어서 소름
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
함수의 리턴값에 대해서 사용하지 않아도 경고문을 표시하지 않는 @discardableResult
어노테이션을 사용한 이유는 아래의 코드처럼 메서드 체이닝으로 보다 간단하게 사용하면서도 경고문이 표시되지 않게 하기 위함이었습니다.
메서드 체이닝을 하기 위해서는 인스턴스를 메서드의 리턴값으로 내보내야 하는데요.
만약 메서드 체이닝이 아닌 형태로 구현된다면 빌더의 구현이 아래와 같아질 것 입니다.
final class Builder {
// 생략..
// 리턴형이 없는 메서드
func setName(_ name: String) {
self.name = name
}
func setPlaceName(_ placeName: String) {
self.placeName = placeName
}
}
// 실제 사용 시
let builder = Builder()
builder.setName(name)
builder.setPlaceName(place.location)
return builder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 ... 메서드 체이닝을 하려면 무조건 리턴값이 존재해야 하는군요! 좋은 정보 감사합니다 👍
return AddPromiseRequestModel.Builder() | ||
.setId(meetingID) | ||
.setName(name) | ||
.setTime(time) | ||
.setPlaceName(place.location) | ||
.setAddress(place.address ?? "") | ||
.setRoadAddress(place.roadAddress ?? "") | ||
.setCoordinates(x: place.x, y: place.y) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
let meetingID: Int | ||
let name: String | ||
let place: Place | ||
let dateString: String | ||
let members: [Member] | ||
|
||
private let builder: AddPromiseRequestModel.Builder | ||
private let service: SelectPenaltyServiceType | ||
private let levelRelay = BehaviorRelay(value: "") | ||
private let penaltyRelay = BehaviorRelay(value: "") | ||
private let newPromiseRelay = BehaviorRelay<AddPromiseResponseModel?>(value: nil) | ||
|
||
init( | ||
meetingID: Int, | ||
name: String, | ||
place: Place, | ||
dateString: String, | ||
members: [Member], | ||
builder: AddPromiseRequestModel.Builder, | ||
service: SelectPenaltyServiceType | ||
) { | ||
self.meetingID = meetingID | ||
self.name = name | ||
self.place = place | ||
self.dateString = dateString | ||
self.members = members | ||
self.builder = builder | ||
self.service = service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
너무 간편해졌네요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
빌더 패턴.. 오렵당 수고하셨어유~~
private var y = 0.0 | ||
private var participants = [Int]() | ||
|
||
@discardableResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
방금 막 아요 코드리뷰하면서 @discardableResult
보고 똑같이 리뷰 남겼는데 여기 또 있어서 소름
🔗 연결된 이슈
📄 작업 내용
💻 주요 코드 설명
AddPromiseRequestModel 내용에 따른 빌더 객체 구현과 사용
AddPromiseRequestModelBuilder.swift