Skip to content

Conversation

@gutenLEE
Copy link

@gutenLEE gutenLEE commented Mar 6, 2024

๋‚ด์ผ์ด ์—ฐ์žฅํ•ด์ฃผ์‹  ์‹ค์‹œ๊ฐ„ ๋ฆฌ๋ทฐ ์‹ ์ฒญ ๋งˆ์ง€๋ง‰๋‚ ์ด๋ผ ๊ธ‰ํ•˜๊ฒŒ ๊ฐœ๋ฐœํ–ˆ๋„ค์š” ใ… ใ… 
๋งˆ์ง€๋ง‰ ๋ฆฌ๋ทฐ ์ž˜ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค!

fare += distanceFare.calculateFare(this);
}
addExtraFare();
this.fare = discount(discountCondition);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋‹ค์‹œ๋ณด๋‹ˆ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜์—ฌ ์žฌํ• ๋‹น ๋ณด๋‹ค๋Š” discount() ๋‚ด๋ถ€์—์„œ ์…‹ํŒ…ํ•ด์ฃผ๋Š”๊ฒŒ ์ข‹์•˜์„๋“ฏํ•ฉ๋‹ˆ๋‹ค

Comment on lines +30 to 37
private void addExtraFare() {
HashSet<LineFare> fares = new HashSet<>(lineFares);
for (LineFare lineFare : fares) {
if (lineFare.hasExtraFare()) {
addFare(lineFare.getExtraFare());
}
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ตฌ๊ฐ„์ด ์†ํ•œ ๋ผ์ธ์˜ ์ถ”๊ฐ€์š”๊ธˆ์„ ๊ฐ€์ ธ์™€์•ผ ํ•ด์„œ ์ด๋ ‡๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค...
์ด ๋ถ€๋ถ„์—์„œ ์‹œ๊ฐ„์ด ๋งŽ์ด ๊ฑธ๋ ธ๋„ค์š” !

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SectionEdge๊ฐ€ ์š”๊ธˆ์„ ์•Œ์•„์•ผ ํ•˜๋Š”๊ฒŒ ๋งž๋‚˜ ๊ณ ๋ฏผ์ด ๋งŽ์ด ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

Copy link

@junwoochoi junwoochoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•ˆ๋…•ํ•˜์„ธ์š”! ๋ช‡๊ฐ€์ง€ ์ถ”๊ฐ€๋กœ ํ™•์ธํ•ด๋ณด์‹œ๋ฉด ์ข‹์„ ๋ถ€๋ถ„๋“ค์ด ์žˆ์–ด์„œ ์ฝ”๋ฉ˜ํŠธ ๋“œ๋ ธ์Šต๋‹ˆ๋‹ค!
ํ™•์ธ ํ›„ ๋‹ค์‹œ ์š”์ฒญ ์ฃผ์„ธ์š” ~

Comment on lines +8 to +11
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface PathAuthenticationPrincipal {
}

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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DistanceFareTest์ค‘์— 2๊ฐœ ํ…Œ์ŠคํŠธ์ผ€์ด์Šค๊ฐ€ ๊นจ์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ํ™•์ธ ํ›„ ์ˆ˜์ • ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค~

  • @ParameterizedTest๋ฅผ ํ™œ์šฉํ•ด๋ณด์‹œ๋Š” ๊ฒƒ๋„ ์ถ”์ฒœ๋“œ๋ ค์š”!

Comment on lines +22 to +26
@RequestParam int source,
@RequestParam int target,
@RequestParam PathType type,
@PathAuthenticationPrincipal UserDetail userDetail) {
return ResponseEntity.ok(pathService.searchPath(source, target, type, userDetail));

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 {

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/

Comment on lines +34 to +42
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()));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ตœ์†Œ์‹œ๊ฐ„ ๊ธฐ์ค€์œผ๋กœ ์กฐํšŒํ•˜๊ฑฐ๋‚˜, ์ตœ๋‹จ๊ฑฐ๋ฆฌ ๊ธฐ์ค€์œผ๋กœ ์กฐํšŒํ•˜๊ฑฐ๋‚˜ ์š”๊ธˆ์€ ํ•ญ์ƒ ์ตœ๋‹จ๊ฑฐ๋ฆฌ ๊ธฐ์ค€์œผ๋กœ ๊ณ„์‚ฐ์ด ๋˜์–ด์•ผํ•ฉ๋‹ˆ๋‹ค!
์ง€ํ•˜์ฒ  ์šด์ž„์€ ๊ฑฐ๋ฆฌ๋น„๋ก€์ œ๋กœ ์ฑ…์ •๋ฉ๋‹ˆ๋‹ค. (์‹ค์ œ ๊ฒฝ๋กœ๊ฐ€ ์•„๋‹Œ ์ตœ๋‹จ๊ฑฐ๋ฆฌ ๊ธฐ์ค€)

And ์ง€ํ•˜์ฒ  ์ด์šฉ ์š”๊ธˆ 3250์›๋„ ํ•จ๊ป˜ ์‘๋‹ตํ•จ


Scenario: ์„ฑ์ธ ์œ ์ €๊ฐ€ ๋‘ ์—ญ์˜ ๋…ธ์„ ์ค‘ ์ถ”๊ฐ€ ํ• ๋‹น ๊ธˆ์•ก์ด ์žˆ๋Š” ๊ฒฝ์šฐ ์ตœ์†Œ ์‹œ๊ฐ„ ๊ฒฝ๋กœ๋ฅผ ์กฐํšŒ

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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calculateFare๊ฐ€ ์™ธ๋ถ€์—์„œ ์—ฌ๋Ÿฌ๋ฒˆ ํ˜ธ์ถœ๋˜๋ฉด ๋‚ด๋ถ€๊ฐ’์ด ๊ณ„์† ๋ณ€๊ฒฝ๋ ๊ฑฐ๊ฐ™์€๋ฐ ํ•„๋“œ๋ณ€์ˆ˜๋กœ fare๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๊ฒƒ๊ณผ ๋งค๋ฒˆ ๊ณ„์‚ฐํ•˜๋Š” ๊ฒƒ์€ ์–ด๋–ค ์ฐจ์ด๊ฐ€ ์žˆ์„๊นŒ์š”~?

Comment on lines +31 to +34
HashSet<LineFare> fares = new HashSet<>(lineFares);
for (LineFare lineFare : fares) {
if (lineFare.hasExtraFare()) {
addFare(lineFare.getExtraFare());

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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeenagerDiscountCondition๊ณผ ๋‹ค๋ฅธ ํด๋ž˜์Šค๋กœ ๋‚˜๋ˆ ์งˆ ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”? ํ•˜๋‚˜์˜ ๊ตฌํ˜„์ฒด๋กœ ๊ด€๋ฆฌํ•ด๋ด๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค

Comment on lines +11 to +13
public boolean support() {
return true;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

support๊ฐ€ ์–ด๋–ค ์ด์œ ๋กœ ์กด์žฌํ•˜๋Š”๊ฑธ๊นŒ์š”?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์„ฑ์ธ์˜ ๊ฒฝ์šฐ๋Š” ํ• ์ธ์„ ์ œ๊ณตํ•˜์ง€ ์•Š๋Š”๋‹ค ์˜๋ฏธ์˜€์Šต๋‹ˆ๋‹ค

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants