-
Notifications
You must be signed in to change notification settings - Fork 203
๐ 3๋จ๊ณ - ์๊ธ ์ ์ฑ ์ถ๊ฐ #468
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
base: gutenlee
Are you sure you want to change the base?
Conversation
This reverts commit bac0da4.
- ๋ ธ์ ๋ณ ์ถ๊ฐ ์๊ธ
| fare += distanceFare.calculateFare(this); | ||
| } | ||
| addExtraFare(); | ||
| this.fare = discount(discountCondition); |
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.
๋ค์๋ณด๋ ๊ฐ์ ๋ฐํํ์ฌ ์ฌํ ๋น ๋ณด๋ค๋ discount() ๋ด๋ถ์์ ์ ํ ํด์ฃผ๋๊ฒ ์ข์์๋ฏํฉ๋๋ค
| private void addExtraFare() { | ||
| HashSet<LineFare> fares = new HashSet<>(lineFares); | ||
| for (LineFare lineFare : fares) { | ||
| if (lineFare.hasExtraFare()) { | ||
| addFare(lineFare.getExtraFare()); | ||
| } | ||
| } | ||
| } |
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.
SectionEdge๊ฐ ์๊ธ์ ์์์ผ ํ๋๊ฒ ๋ง๋ ๊ณ ๋ฏผ์ด ๋ง์ด ๋์์ต๋๋ค.
junwoochoi
left a comment
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.
์๋
ํ์ธ์! ๋ช๊ฐ์ง ์ถ๊ฐ๋ก ํ์ธํด๋ณด์๋ฉด ์ข์ ๋ถ๋ถ๋ค์ด ์์ด์ ์ฝ๋ฉํธ ๋๋ ธ์ต๋๋ค!
ํ์ธ ํ ๋ค์ ์์ฒญ ์ฃผ์ธ์ ~
| @Target(ElementType.PARAMETER) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| public @interface PathAuthenticationPrincipal { | ||
| } |
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.
๊ธฐ์กด AuthenticationPrincipal์ ํ์ฉํ์ง ์์ ์ด์ ๊ฐ ์๋์? ๐
| for (DistanceFare fare : distanceFare) { | ||
| sum += fare.calculateFare(16); | ||
| for (DistanceFare sut : distanceFare) { | ||
| sum += sut.calculateFare(FareSteps.buildFare(9)); |
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.
DistanceFareTest์ค์ 2๊ฐ ํ ์คํธ์ผ์ด์ค๊ฐ ๊นจ์ง๊ณ ์์ต๋๋ค. ํ์ธ ํ ์์ ๋ถํ๋๋ฆฝ๋๋ค~
@ParameterizedTest๋ฅผ ํ์ฉํด๋ณด์๋ ๊ฒ๋ ์ถ์ฒ๋๋ ค์!
| @RequestParam int source, | ||
| @RequestParam int target, | ||
| @RequestParam PathType type, | ||
| @PathAuthenticationPrincipal UserDetail userDetail) { | ||
| return ResponseEntity.ok(pathService.searchPath(source, target, type, userDetail)); |
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.
๋ก๊ทธ์ธํ์ง ์์ ์ ์ ๋ Path์กฐํ๊ฐ ๊ฐ๋ฅํด์ผํฉ๋๋ค!
@RequestParam์ requiredํ๋์ ๊ฐ์ ๋ฐฉ์์ ๋์
ํ๋๊ฒ๋ ๊ณ ๋ คํด๋ณด๋ฉด ์ด๋จ๊น์?
| int fare = 0; | ||
| public void calculateFare(int distance, List<DistanceFare> distanceFares) { | ||
|
|
||
| public class Fare implements Discountable { |
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.
์ํฉ๋ง๋ค ๋ค๋ฅด์ง๋ง, ์์๋ณด๋ค๋ ์กฐํฉ์ ์ฌ์ฉํ๋ ๊ฒ์ด ๋ ์ ์ฐํ ๊ตฌ์กฐ๊ฐ ๋ ์๋ ์๋ค๋ ์ ๋ ํ์ธํด๋ณด์๋ฉด ์ข๊ฒ ์ต๋๋ค :)
https://tecoble.techcourse.co.kr/post/2020-05-18-inheritance-vs-composition/
| public PathsResponse searchPath(long source, long target, PathType pathType, UserDetail userDetail) { | ||
| try { | ||
| PathFinder pathFinder = createPathFinder(lineRepository.findAll(), pathType); | ||
| PathsDto pathsDto = pathFinder.findPath(getStation(source), getStation(target)); | ||
| Fare fare = new Fare(); | ||
| fare.calculateFare(pathsDto.getDistance(), DistanceFareFactory.createDistanceFare()); | ||
| List<SectionEdge> sectionEdges = pathsDto.getSectionEdges(); | ||
| List<LineFare> lineFares = sectionEdges.stream().map(SectionEdge::getLineFare).collect(Collectors.toList()); | ||
|
|
||
| Fare fare = new Fare(lineFares, pathsDto.getDistance()); | ||
| fare.calculateFare(DistanceFareFactory.createDistanceFare(), DiscountConditionFactory.createDiscountCondition(userDetail.getAge())); |
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.
์ต์์๊ฐ ๊ธฐ์ค์ผ๋ก ์กฐํํ๊ฑฐ๋, ์ต๋จ๊ฑฐ๋ฆฌ ๊ธฐ์ค์ผ๋ก ์กฐํํ๊ฑฐ๋ ์๊ธ์ ํญ์ ์ต๋จ๊ฑฐ๋ฆฌ ๊ธฐ์ค์ผ๋ก ๊ณ์ฐ์ด ๋์ด์ผํฉ๋๋ค!
์งํ์ฒ ์ด์์ ๊ฑฐ๋ฆฌ๋น๋ก์ ๋ก ์ฑ
์ ๋ฉ๋๋ค. (์ค์ ๊ฒฝ๋ก๊ฐ ์๋ ์ต๋จ๊ฑฐ๋ฆฌ ๊ธฐ์ค)
| And ์งํ์ฒ ์ด์ฉ ์๊ธ 3250์๋ ํจ๊ป ์๋ตํจ | ||
|
|
||
|
|
||
| Scenario: ์ฑ์ธ ์ ์ ๊ฐ ๋ ์ญ์ ๋ ธ์ ์ค ์ถ๊ฐ ํ ๋น ๊ธ์ก์ด ์๋ ๊ฒฝ์ฐ ์ต์ ์๊ฐ ๊ฒฝ๋ก๋ฅผ ์กฐํ |
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.
์๋๋ฆฌ์ค๋ ์ฑ์ธ์ ์ ์ธ๋ฐ, ํ๋จ์ when์์๋ ์ด๋ฆฐ์ด๋ก ๋์ด์๋ค์ ๐ข
| } | ||
|
|
||
|
|
||
| public void calculateFare(List<DistanceFare> distanceFares, DiscountCondition discountCondition) { |
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.
calculateFare๊ฐ ์ธ๋ถ์์ ์ฌ๋ฌ๋ฒ ํธ์ถ๋๋ฉด ๋ด๋ถ๊ฐ์ด ๊ณ์ ๋ณ๊ฒฝ๋ ๊ฑฐ๊ฐ์๋ฐ ํ๋๋ณ์๋ก fare๋ฅผ ๊ฐ์ง๊ณ ์๋ ๊ฒ๊ณผ ๋งค๋ฒ ๊ณ์ฐํ๋ ๊ฒ์ ์ด๋ค ์ฐจ์ด๊ฐ ์์๊น์~?
| HashSet<LineFare> fares = new HashSet<>(lineFares); | ||
| for (LineFare lineFare : fares) { | ||
| if (lineFare.hasExtraFare()) { | ||
| addFare(lineFare.getExtraFare()); |
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.
๊ฒฝ๋ก ์ค์ ๋ ธ์ ์ถ๊ฐ์๊ธ์ด ์ฌ๋ฌ๊ฑด ์๋ ๊ฒฝ์ฐ ๊ทธ์ค์ ๊ฐ์ฅ ๋์ ์ถ๊ฐ์๊ธ๋ง ์ ์ฉ๋์ด์ผํฉ๋๋ค.
๊ฒฝ๋ก ์ค ์ถ๊ฐ์๊ธ์ด ์๋ ๋
ธ์ ์ ํ์น ํ์ฌ ์ด์ฉ ํ ๊ฒฝ์ฐ ๊ฐ์ฅ ๋์ ๊ธ์ก์ ์ถ๊ฐ ์๊ธ๋ง ์ ์ฉ
ex) 0์, 500์, 900์์ ์ถ๊ฐ ์๊ธ์ด ์๋ ๋
ธ์ ๋ค์ ๊ฒฝ์ ํ์ฌ 8km ์ด์ฉ ์ 1,250์ -> 2,150์
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| public class ChildDiscountCondition implements DiscountCondition { |
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.
TeenagerDiscountCondition๊ณผ ๋ค๋ฅธ ํด๋์ค๋ก ๋๋ ์ง ์ด์ ๊ฐ ์์๊น์? ํ๋์ ๊ตฌํ์ฒด๋ก ๊ด๋ฆฌํด๋ด๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค
| public boolean support() { | ||
| return true; | ||
| } |
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.
support๊ฐ ์ด๋ค ์ด์ ๋ก ์กด์ฌํ๋๊ฑธ๊น์?
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.
์ฑ์ธ์ ๊ฒฝ์ฐ๋ ํ ์ธ์ ์ ๊ณตํ์ง ์๋๋ค ์๋ฏธ์์ต๋๋ค
๋ด์ผ์ด ์ฐ์ฅํด์ฃผ์ ์ค์๊ฐ ๋ฆฌ๋ทฐ ์ ์ฒญ ๋ง์ง๋ง๋ ์ด๋ผ ๊ธํ๊ฒ ๊ฐ๋ฐํ๋ค์ ใ ใ
๋ง์ง๋ง ๋ฆฌ๋ทฐ ์ ๋ถํ๋๋ฆฝ๋๋ค!