-
Notifications
You must be signed in to change notification settings - Fork 297
3단계 - 수강신청(DB 적용) #769
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
Open
heewonham
wants to merge
6
commits into
next-step:heewonham
Choose a base branch
from
heewonham:step3
base: heewonham
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
3단계 - 수강신청(DB 적용) #769
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
845e2a8
feat : (review) 값 객체 equal, hashcode 추가
fbca015
feat : (review) students 일급 컬렉션 추가 및 테스트 코드 추가
37e1180
feat : (review) 상수 위치 변경, 의미있는 상수 이름 변경, 함수 추가
623f840
feat : session Repository 및 테스트 코드 추가
c17e5ec
feat : sessionStudent repository 및 테스트 코드 추가
f8e00f3
feat : (review) namedjdbctemplate 사용 및 sessionstudent 레포삭제
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,5 @@ out/ | |
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
/bin/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package nextstep.courses.domain; | ||
|
||
public class Student { | ||
Long id; | ||
public Student() { | ||
} | ||
public Student(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public boolean contains(Long studentId) { | ||
return id.equals(studentId); | ||
} | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Student student = (Student) o; | ||
return id != null && id.equals(student.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return id != null ? id.hashCode() : 0; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package nextstep.courses.domain; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.Collections; | ||
|
||
public class Students { | ||
private Set<Student> students = new HashSet<>(); | ||
|
||
public void addStudent(Student student) { | ||
if (contains(student)) { | ||
throw new IllegalArgumentException("이미 등록된 학생입니다."); | ||
} | ||
students.add(student); | ||
} | ||
|
||
public void removeStudent(Student student) { | ||
students.remove(student); | ||
} | ||
|
||
public boolean contains(Student student) { | ||
return students.stream() | ||
.anyMatch(s -> s.equals(student)); | ||
} | ||
|
||
public int size() { | ||
return students.size(); | ||
} | ||
|
||
public Set<Student> getStudents() { | ||
return Collections.unmodifiableSet(students); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package nextstep.courses.domain; | ||
|
||
import java.util.Objects; | ||
|
||
public class TuitionFee { | ||
private final int amount; | ||
|
||
|
@@ -10,7 +12,24 @@ public TuitionFee(int amount) { | |
this.amount = amount; | ||
} | ||
|
||
public int getAmount() { | ||
public boolean isSameAmount(int amount) { | ||
return this.amount == amount; | ||
} | ||
|
||
public int getValue() { | ||
return amount; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof TuitionFee)) return false; | ||
TuitionFee that = (TuitionFee) o; | ||
return amount == that.amount; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
Comment on lines
+23
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 리뷰 반영 잘 되었네요 😄 |
||
return Objects.hash(amount); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
#728 (comment)
#728 (comment)
이 두 부분이 약간 상충되는 것 같아 질문드립니다.
어떤 부분은 get을 쓰고 어떤 부분은 이렇게 함수를 만드는데 구분할 수 있는 방법은 무엇일까요?
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.
그럼에도 불구하고 게터만으로 객체의 상태를 검증하기 어려운 경우,
테스트를 목적으로 하는 메서드를
public
대신protected
로 선언하는 방법도 있습니다.보통 테스트 클래스는 테스트 대상 클래스와 같은 패키지에 위치하므로,
protected
메서드에도 접근할 수 있어서요.이러면 테스트의 편의성을 확보하면서도, 외부에서의 불필요한 접근은 제한할 수 있게됩니다 😄
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.
@nooose 아하 이해했습니다. 도메인 객체 책임에 해당하는지를 생각해보면 되겠군요!!
상세한 설명 감사합니다 🙏