Skip to content

김동현 chap5 구현 - #7

Open
dh0304 wants to merge 38 commits into
java-web-programming-nextstep-study:mainfrom
dh0304:dh-chap5
Open

dh0304 wants to merge 38 commits into
java-web-programming-nextstep-study:mainfrom
dh0304:dh-chap5

Conversation

@dh0304

@dh0304 dh0304 commented Aug 12, 2024

Copy link
Copy Markdown
Contributor

No description provided.

@Override
protected void doGet(HttpRequest httpRequest, HttpResponse httpResponse) {

private BiConsumer<HttpRequest, HttpResponse> wrap(BiConsumerWithIOException<HttpRequest, HttpResponse> consumer) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[질문] 처음 보는 형태의 예외처리 코드네요, 어떤 의도로 이 코드를 사용하신건지에 대해 궁금합니다!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

저도 처음 써봅니다 ㅋㅋㅋ

함수형 인터페이스는 예외를 던질 수 없어서 wrap메서드로 감싸서 던지게 설계했습니다.

요구조건 사항을 따르다보니, 컨트롤러에서 dto를 의존하는 것이 아닌, 실제 요청과 응답을 다루는 객체를 다루도록 설계했습니다.
기존에 작성된 컨트롤러가 RequestDto와 ResponseDto를 인자로 받는 함수형 인터페이스를 사용하고 있었고, 설계가 바뀜에 따라서 HttpRequest 와 HttpResponse를 다루게 되었습니다. 이 두 객체는 입출력 예외를 밖으로 던지고 있어서 예외 처리가 필요한 시점이였고, 저는 예외를 상위에서 공통으로 처리할 생각이기때문에 예외를 또 던져야 하는 상황이였습니다.

자바에서 지원하는 함수형 인터페이스는 예외를 던질 수 없어서 커스텀 함수형 인터페이스를 만들고 예외를 던질 수 있는 wrap메서드를 만들어서 구현했습니다.

이 책을 통해서 코드를 구현할 때 가장 나은 방법을 찾아가는 것이 아닌, 요구사항이 바뀌었을 때 기존보다 조금이라도 나은 방법을 찾다보니까 나오게 된 코드인 것 같아요. 좋은 코드인것 같진 않은데 바꾸다 보니 이렇게 만들어졌네요.....ㅋㅋㅋㅋ

import java.io.IOException;
import java.nio.file.Files;

public class StaticFileHandler {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[칭찬] 정적파일처리기를 따로 Class 를 만들어서 분리하니 좋네요!


@Test
public void 유저_폼을_가져온다() {
public void 유저_폼을_가져온다() throws IOException {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[칭찬] HttpRequest와 HttpResponse를 직접 만들어서 테스트하니, 컨트롤러 테스트가 가능하군요! 좋습니다~!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[질문] 저번이랑 Controller 쪽이 달라져서 안 맞아서 그런지 Exception 처리하는 클래스를 왜 사용하지 않으셨는지 궁금하네요.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[칭찬] 동현님 코드 보면서 항상 많이 배우고, 참고가 되고 있습니다. UserController에 대한 대략적인 설명과 의도를 한 번 일요일에 설명해주시면 좋을 것 같아요

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