Skip to content

[김민수] Sprint 2 #28

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
wants to merge 5 commits into
base: 김민수
Choose a base branch
from

Conversation

NanHangBok
Copy link
Collaborator

요구사항

기본

File IO를 통한 데이터 영속화

  • 다음의 조건을 만족하는 서비스 인터페이스의 구현체를 작성하세요.
  • 클래스 패키지명: com.sprint.mission.discodeit.service.file
  • 클래스 네이밍 규칙: File[인터페이스 이름]
  • JCF 대신 FileIO와 객체 직렬화를 활용해 메소드를 구현하세요.
  • Application에서 서비스 구현체를 File*Service로 바꾸어 테스트해보세요.

서비스 구현체 분석

  • JCFService 구현체와 FileService 구현체를 비교하여 공통점과 차이점을 발견해보세요.
  • "비즈니스 로직"과 관련된 코드를 식별해보세요.
  • "저장 로직"과 관련된 코드를 식별해보세요.

레포지토리 설계 및 구현

  • "저장 로직"과 관련된 기능을 도메인 모델 별 인터페이스로 선언하세요.
    • 인터페이스 패키지명: com.sprint.mission.discodeit.repository
    • 인터페이스 네이밍 규칙: [도메인 모델 이름]Repository
  • 다음의 조건을 만족하는 레포지토리 인터페이스의 구현체를 작성하세요.
    • 클래스 패키지명: com.sprint.mission.discodeit.repository.jcf
    • 클래스 네이밍 규칙: JCF[인터페이스 이름]
    • 기존에 구현한 JCF*Service 구현체의 "저장 로직"과 관련된 코드를 참고하여 구현하세요.
  • 다음의 조건을 만족하는 레포지토리 인터페이스의 구현체를 작성하세요.
    • 클래스 패키지명: com.sprint.mission.discodeit.repository.file
    • 클래스 네이밍 규칙: File[인터페이스 이름]
    • 기존에 구현한 File*Service 구현체의 "저장 로직"과 관련된 코드를 참고하여 구현하세요.

심화

관심사 분리를 통한 레이어 간 의존성 주입

  • 다음의 조건을 만족하는 서비스 인터페이스의 구현체를 작성하세요.

    • 클래스 패키지명: com.sprint.mission.discodeit.service.basic
    • 클래스 네이밍 규칙: Basic[인터페이스 이름]
    • 기존에 구현한 서비스 구현체의 "비즈니스 로직"과 관련된 코드를 참고하여 구현하세요.
    • 필요한 Repository 인터페이스를 필드로 선언하고 생성자를 통해 초기화하세요.
    • "저장 로직"은 Repository 인터페이스 필드를 활용하세요. (직접 구현하지 마세요.)
  • Basic*Service 구현체를 활용하여 테스트해보세요.

  • JCF*Repository 구현체를 활용하여 테스트해보세요.

  • File*Repository 구현체를 활용하여 테스트해보세요.

  • 이전에 작성했던 코드(JCFService 또는 FileService)와 비교해 어떤 차이가 있는지 정리해보세요.

주요 변경사항

  • 파일 기반 서비스 추가
  • 파일 기반 과 JCF 기반 서비스의 공동 서비스 baisc 서비스 추가
  • 파일 기반 레포지토리 추가
  • JCF 기반 레포지토리 추가
  • psvm 에 테스트 코드 추가

멘토에게

  • 셀프 코드 리뷰를 통해 질문 이어가겠습니다.

Comment on lines +54 to +63
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
BasedEntity that = (BasedEntity) o;
return Objects.equals(getId(), that.getId());
}

@Override
public int hashCode() {
return Objects.hashCode(getId());
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

equals랑 hashCode 재정의해서 쓰는 것 굉장히 좋습니다.

Comment on lines +57 to +84
public void addUser(User user) {
if (this.user == null){
this.user = user;
user.addMessage(this);
}
}

// 작성된 채널
public void addChannel(Channel channel) {
if (this.channel == null){
this.channel = channel;
channel.addMessage(this);
}
}

// 유저가 삭제하거나 유저가 삭제된 경우
public void removeUser() {
if (this.user != null) {
this.user = null;
}
}

// 채널에서 삭제된 경우
public void removeChannel() {
if (this.channel != null) {
this.channel = null;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

여기도 분기 안에서는 예외 처리 밖에서는 비지니스 로직 수행하는 식으로 변경해보세요!

try (FileInputStream fis = new FileInputStream(FILE_PATH);
ObjectInputStream ois = new ObjectInputStream(fis)) {
list = (List<Channel>) ois.readObject();
} catch (IOException | ClassNotFoundException e) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

에러는 각각 처리해주시는게 더 좋습니다.

List<Message> list = findAll();
if(list.stream().anyMatch(message::equals)){
List<Message> updatedList = list.stream().map(c -> c.equals(message) ? message : c)
.collect(Collectors.toList());
Copy link
Collaborator

Choose a reason for hiding this comment

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

불변객체를 리턴하실거라면 아래처럼 수정해주세요. 나머지 코드들도 마찬가지입니다.

Suggested change
.collect(Collectors.toList());
.toList();
Suggested change
.collect(Collectors.toList());
.collect(Collectors.toList());
Suggested change
.collect(Collectors.toList());
.collect(Collectors.toList());

// 채널 삭제
@Override
public void deleteChannel(Channel channel) {
validatedChannel(channel);
Copy link
Collaborator

Choose a reason for hiding this comment

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

메서드명 수정해주세요.

Suggested change
validatedChannel(channel);
validateChannel(channel);
Suggested change
validatedChannel(channel);
validatedChannel(channel);
Suggested change
validatedChannel(channel);
validatedChannel(channel);

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.

4 participants