forked from knh4437/java-lotto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(OutputView): LottoApplication에서 로또 출력하는 기능을 분리함
- Lotto의 number정보를 주는 getter를 만들지 않고 dto를 만들어 줌 - 다른 객체에서 numbers를 사용하지 않도록 하기 위해 dto를 구현함 - OutputView를 만들어 1차적으로 Lotto 출력하는 부분을 비즈니스 로직에서 분리함 - Lotto, LottoShop에서 UI와 관련된 메서드를 삭제함
- Loading branch information
1 parent
c8bd3b3
commit 1484b17
Showing
8 changed files
with
77 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,16 @@ | ||
package lotto.lotto.dto; | ||
|
||
import java.util.List; | ||
|
||
public class LottoDto { | ||
|
||
private List<Integer> numbers; | ||
|
||
public LottoDto(List<Integer> numbers) { | ||
this.numbers = numbers; | ||
} | ||
|
||
public List<Integer> getNumbers() { | ||
return numbers; | ||
} | ||
} |
This file contains 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,20 @@ | ||
package lotto.lotto.dto; | ||
|
||
import lotto.lotto.Lotto; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class LottoListDto { | ||
|
||
private List<LottoDto> lottoDtos; | ||
|
||
public LottoListDto(List<Lotto> lottos) { | ||
this.lottoDtos = lottos.stream() | ||
.map(lotto -> lotto.getLottoDto()) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public List<LottoDto> getLottoDtos() { | ||
return lottoDtos; | ||
} | ||
} |
This file contains 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,32 @@ | ||
package lotto.view; | ||
|
||
import device.output.Output; | ||
import lotto.lotto.dto.LottoDto; | ||
import lotto.lotto.dto.LottoListDto; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class OutputView { | ||
|
||
private final Output output; | ||
|
||
public OutputView(Output output) { | ||
this.output = output; | ||
} | ||
|
||
public void printLottos(LottoListDto lottoListDto) { | ||
List<LottoDto> lottoDtos = lottoListDto.getLottoDtos(); | ||
|
||
output.print("\n" + lottoDtos.size() + "개를 구매했습니다."); | ||
for (LottoDto lottoDto : lottoDtos) { | ||
output.print(getNumbers(lottoDto)); | ||
} | ||
} | ||
|
||
private String getNumbers(LottoDto lottoDto) { | ||
return lottoDto.getNumbers().stream() | ||
.sorted() | ||
.map(number -> String.valueOf(number)) | ||
.collect(Collectors.joining(", ","[","]")); | ||
} | ||
} |
This file contains 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 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