Skip to content

CLI 자바 서비스 만들기 - 김정환#3

Open
kjh3165 wants to merge 16 commits into
hoehoeabi:mainfrom
kjh3165:main
Open

CLI 자바 서비스 만들기 - 김정환#3
kjh3165 wants to merge 16 commits into
hoehoeabi:mainfrom
kjh3165:main

Conversation

@kjh3165
Copy link
Copy Markdown

@kjh3165 kjh3165 commented Apr 16, 2026

CLIPost


🎯 개요

이 과제는 Java 콘솔 프로그램으로 간단한 텍스트 게시판을 구현하는 프로젝트입니다.
Java 기본 문법, 클래스 및 객체지향 설계, 사용자 입력 처리, 그리고 데이터 저장 구조(ArrayList 등)를 연습합니다.


🧩 전체 기능 및 명령어

  • 게시글 작성 :write
    • 명령어 입력 시 제목/내용을 받아 새 게시글 생성
  • 게시글 목록 :list
    • 명령어 입력 시 모든 게시글을 번호 역순으로 출력
  • 게시글 상세보기 : detail [id]
    • 명령어로 특정 게시글 내용을 전체 확인
  • 게시글 수정 : update [id]
    • 명령어로 제목/내용을 수정
  • 게시글 삭제 : delete [id]
    • 명령어로 해당 글 삭제
  • 명령어 목록 : help
    • 명령어들을 확인
  • 종료 : exit
    • 명령어로 프로그램 종료

게시글 객체 구조

class Article {
    int id;
    String title;
    String content;
    LocalDateTime regDate;
    LocalDateTime modDate;
}

⚙️ 주요 클래스 및 파일 구조 예시

src
 └─main
     └─java
         └─com
             │  App.java
             │  AppContext.java
             │  Main.java
             │  
             ├─Article
             │      Article.java
             │      ArticleController.java
             │      ArticleService.java
             │      
             └─util
                     Rq.java

🧠 메서드 설계 예시

메서드명 설명
run() 앱 실행 루프 (입력 대기 및 명령어 처리)
writeArticle() 게시글 작성 처리
listArticles() 게시글 목록 출력
showDetail(int id) 특정 글 상세 내용 출력
updateArticle(int id) 게시글 수정 처리
deleteArticle(int id) 게시글 삭제 처리
checkId(int id) 게시글 존재 여부 확인 및 반환
showCommands() 명령어들 출력
write(String title, String content) 실제 게시글 작성 처리
update(Article article, String newTitle, String newContent) 실제 게시글 수정 처리
delete(Article article) 실제 게시글 삭제 처리

💬 실행 예시

== 자바 텍스트 게시판 시작 ==
명령어 모음
등록: write
목록: list
상세: detail [id]
수정: update [id]
삭제: delete [id]
도움: help
종료: exit

명령어) write
제목: first
내용: class
1번 게시글이 등록되었습니다.

명령어) write
제목: second
내용: class2
2번 게시글이 등록되었습니다.

명령어) update 1
제목(기존) : first
제목: first upadte
내용(기존) : class
내용: class update
1번 게시글이 수정되었습니다.

명령어) list
 번호 | 제목 | 등록일 | 수정일
--------------------------------
 2 | second | 2026-04-13 16:38 | 
 1 | first upadte | 2026-04-13 16:38 | 2026-04-13 16:39
 
명령어: delete 2
2번 게시글이 삭제되었습니다.

명령어) list
 번호 | 제목 | 등록일 | 수정일
--------------------------------
 1 | first upadte | 2026-04-13 16:38 | 2026-04-13 16:39
 
명령어) exit
프로그램을 종료합니다.


public class Article{

private final int id;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

불변값이니까 final 붙여놓는거 생각 못했었는데 좋은 방식이라 생각합니다

import java.util.Scanner;

public class ArticleController {
Scanner scanner = AppContext.scanner;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

AppContext에서 생성자 주입방식으로 주입해줬으면 테스트 하기에도 용이할거같아요


public void showDetail(int id){
Article article = checkId(id);
if(article == null)
Copy link
Copy Markdown
Owner

@hoehoeabi hoehoeabi Apr 16, 2026

Choose a reason for hiding this comment

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

찾는 게시글이 있는지 확인하는 일과 화면에 글자를 출력하는 일을 나누어 보는 건 어떨까요?

지금은 서비스 클래스에서 직접 문구를 출력하고 있는데, 나중에 이 프로그램을 '웹 사이트'나 '스마트폰 앱'으로 바꾸게 되면 System.out.println은 화면에 보이지 않게 되거든요.

그래서 서비스는 단순히 '데이터가 있다/없다'만 알려주고, 실제 안내 문구는 사용자와 직접 대화하는 '컨트롤러'에서 담당하게 하면, 나중에 프로그램이 커져도 서비스 코드를 그대로 다시 쓸 수 있어 훨씬 효율적이 될 거같아요

articleList.add(newArticle);
}

public void update(Article article, String newTitle, String newContent){
Copy link
Copy Markdown
Owner

@hoehoeabi hoehoeabi Apr 16, 2026

Choose a reason for hiding this comment

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

Article 객체에서 스스로 수정하는 메서드 만들고 해당 메서드를 호출하는 방식은 어땠을까요?

public void update(String title, String content) {
        this.title = title;
        this.content = content;
        this.modDate = LocalDateTime.now();
    }
``` 이런느낌으로요

Copy link
Copy Markdown
Owner

@hoehoeabi hoehoeabi left a comment

Choose a reason for hiding this comment

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

고생하셨습니다~

@p7548296-afk
Copy link
Copy Markdown

전체적으로 코드가 직관적이고 깔끔해서 읽기 좋았습니다!
생성자나 필드에서 final 키워드를 사용하여 불변성을 고려한 설계가 좋았던 것 같습니다.

Copy link
Copy Markdown

@m1nhy2uk m1nhy2uk left a comment

Choose a reason for hiding this comment

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

CRUD기능구현이 잘 되었고, 예외처리를 하나의 메서드로 묶어서 재사용한점이 인상적입니다.
고생많으셨습니다.


public Article checkId(int id){
if(id == 0){
System.out.println("id를 확인해주세요.\n");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ArticleService는 결과만 반환하고 출력은 ArticleController로 가도 좋을 것 같습니다.

@woo0218
Copy link
Copy Markdown

woo0218 commented Apr 17, 2026

과제에서 원하는 구조에 잘 알맞는 구조로 설계하신것 같습니다. 고생하셨습니다!

@0-0v
Copy link
Copy Markdown

0-0v commented Apr 17, 2026

필드 접근제어자가 전반적으로 잘 되어 있는 것 같습니다! 배워갑니다

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.

6 participants