Skip to content

[정지환] sprint 1 #7

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 3 commits into
base: main
Choose a base branch
from

Conversation

hello13580
Copy link
Collaborator

@hello13580 hello13580 commented Jun 4, 2025

요구사항

기본

프로젝트 초기화

  • IntelliJ를 통해 다음의 조건으로 Java 프로젝트를 생성합니다.
  • IntelliJ에서 제공하는 프로젝트 템플릿 중 Java를 선택합니다.
  • 프로젝트의 경로는 스프린트 미션 리포지토리의 경로와 같게 설정합니다.
  • Create Git Repository 옵션은 체크하지 않습니다.
  • Build system은 Gradle을 사용합니다. Gradle DSL은 Groovy를 사용합니다.
  • JDK 17을 선택합니다.
  • GroupId는 com.sprint.mission로 설정합니다.
  • ArtifactId는 수정하지 않습니다.
  • .gitignore에 IntelliJ와 관련된 파일이 형상관리 되지 않도록 .idea 디렉토리를 추가합니다.

도메인 모델링

  • 디스코드 서비스를 활용해보면서 각 도메인 모델에 필요한 정보를 도출하고, Java Class로 구현하세요.
  • 패키지명: com.sprint.mission.discodeit.entity

도메인 모델 정의

  • 공통
    • id: UUID 타입
    • createdAt, updatedAt: Long 타입
  • User
  • Channel
  • Message

생성자

  • id는 생성자에서 초기화하세요.
  • createdAt은 생성자에서 초기화하세요.
  • 나머지 필드는 파라미터를 통해 초기화하세요.

메소드

  • 각 필드에 대한 Getter 함수
  • 필드 수정용 update 함수

서비스 설계 및 구현

  • 도메인 모델 별 CRUD 인터페이스 선언

    • 패키지명: com.sprint.mission.discodeit.service
    • 네이밍 규칙: [도메인명]Service
  • 인터페이스 구현체 작성

    • 클래스 패키지명: com.sprint.mission.discodeit.service.jcf
    • 클래스 네이밍 규칙: JCF[인터페이스명]
    • Java Collections Framework 활용
    • data 필드를 final로 선언하고 생성자에서 초기화
    • CRUD 메소드 구현

메인 클래스 구현 (JavaApplication)

  • 도메인 별 서비스 구현체 테스트
    • 등록
    • 조회 (단건, 다건)
    • 수정
    • 수정된 데이터 조회
    • 삭제
    • 조회를 통해 삭제되었는지 확인

심화 요구 사항

서비스 간 의존성 주입

  • 도메인 모델 간 관계를 고려해서 검증하는 로직을 추가하고, 테스트해보세요.

주요 변경사항

  • 도메인의 공통 필드를 부모클래스인 baseEntity 로 추출
  • 서비스 구현체 생성을 위한 팩토리 클래스 사용
  • 서비스 구현체에 Singleton 패턴 적용
  • enum을 사용해 유저 상태 구현

스크린샷

image

멘토에게

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

Comment on lines +20 to +25
Scanner sc = new Scanner(System.in);

JCFServiceFactory factory = new JCFServiceFactory();
UserService userService = factory.createUserService();
MessageService messageService = factory.createMessageService();
ChannelService channelService = factory.createChannelService();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Scanner로 분기처리 및 의존성 주입 처리 별도로 팩토리 서비스 만드셔서 처리해준 것 좋습니다

Comment on lines +37 to +71
public List<Channel> getChannels() {
return channels;
}

public List<Message> getMessages() {
return messages;
}

public void updateUserName(String newUserName) {
this.userName = newUserName;
}

public Status getStatus() { return status; }

public void setStatus(Status status) { this.status = status; }

public void addChannel(Channel newChannel){
if(!channels.contains(newChannel)) {
channels.add(newChannel);
newChannel.addUser(this);
}
}

public void removeChannel(Channel newChannel){
if(channels.contains(newChannel)) {
channels.remove(newChannel);
newChannel.removeUser(this);
}
}

public void addMessage(Message newMessage){
this.messages.add(newMessage);
}

public void removeMessage(Message m){ this.messages.remove(m); }
Copy link
Collaborator

Choose a reason for hiding this comment

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

유저 도메인에 두기에는 너무 과도한 책임이라고 보여집니다 removeMesages, getChannels 등
서비스 계층으로 빼는게 나아보여요

Comment on lines +25 to +35
private JCFChannelService(){
data = new ArrayList<>();
this.messageService = JCFMessageService.getInstance();
}

public static JCFChannelService getInstance() {
if (instance == null) {
instance = new JCFChannelService();
}
return instance;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

좋습니다 싱글톤패턴 적용


//싱글톤으로 변경
private static JCFChannelService instance;
private final List<Channel> data;
Copy link
Collaborator

Choose a reason for hiding this comment

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

리스트로 처리한게 좀 아쉽네요 Map을 쓰는게 더 효과적인 탐색이 가능할텐데요

public class JCFMessageService implements MessageService {

private static JCFMessageService instance;
private final List<Message> data;
Copy link
Collaborator

Choose a reason for hiding this comment

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

여기도 마찬가지로 Map

public class JCFUserService implements UserService {

private static JCFUserService instance;
private final List<User> data;
Copy link
Collaborator

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.

2 participants