Skip to content

260616_11_유재우#53

Open
ooweaJ wants to merge 1 commit into
SurvivalCodingCampus:student/11_유재우from
ooweaJ:master
Open

260616_11_유재우#53
ooweaJ wants to merge 1 commit into
SurvivalCodingCampus:student/11_유재우from
ooweaJ:master

Conversation

@ooweaJ

@ooweaJ ooweaJ commented Jun 16, 2026

Copy link
Copy Markdown

260616_11_유재우

📝 과제 정보

  • 교육 주제: 상속, 오버라이딩

📋 체크리스트

  • 코드 컨벤션 준수 (Formatter 적용)
  • 모든 테스트 케이스 통과 (JUnit)

📷 실행 결과 (또는 테스트 결과)

스크린샷 2026-06-16 154335

클래스 다이어그램

스크린샷 2026-06-16 145133

❓질문 및 어려웠던 점

  • JUnit 테스트 작성 중 @DisplayName이 적용되지 않는 것처럼 보여 원인을 찾는 데 시간이 걸렸다.
  • IntelliJ가 테스트를 Gradle Runner로 실행하고 있어 @DisplayName이 보이지 않았음을 확인했다.

🔄 자체 평가 & 회고

  • IntelliJ Runner는 테스트 결과를 개발자 친화적으로 시각화해주고, Gradle Runner는 실제 빌드 도구 기준으로 테스트를 수행한다.

Gradle Runner

테스트 실행
 ↓
Gradle
 ↓
JUnit
 ↓
결과 반환
 ↓
콘솔 출력

IntelliJ Runner

테스트 실행
 ↓
IntelliJ 내부 JUnit Runner
 ↓
JUnit
 ↓
결과 수집
 ↓
IDE가 보기 좋게 가공

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

코드 리뷰 - 상속과 메서드 오버라이딩 구현

🎉 잘 구현된 부분

상속 구조와 계층 설계

  • Hero → Wizard → GreatWizard의 상속 계층이 논리적으로 잘 설계되었습니다.
  • super() 호출을 통해 부모 클래스 생성자를 올바르게 초기화하고 있습니다.

캡슐화 (Encapsulation)

  • Hero의 name, hp, maxhp를 private으로 보호하고, 필요한 getter 메서드(getName(), getHp(), getMaxhp())를 제공하는 방식이 좋습니다.
  • incrementHP() 메서드를 통해 HP 상한선을 초과하지 않도록 유효성 검사를 올바르게 구현했습니다.

메서드 오버라이딩

  • GreatWizard에서 heal() 메서드를 @Override 어노테이션과 함께 올바르게 오버라이드하고, 각 클래스마다 다른 마나 소비량과 힐량을 구현했습니다.
  • 모든 JUnit 테스트가 성공적으로 통과했습니다.

💭 개선을 위한 안내 (소크라테스식 질문)

1. 마나 관리의 캡슐화

  • 현재 Wizard에서 mp 필드를 protected로 선언하고, GreatWizard에서 직접 mp -= 5; 또는 mp -= 50; 형태로 수정하고 있습니다.
  • 질문: "마나 소비" 라는 동작을 별도의 메서드로 분리한다면, 자식 클래스에서 어떤 이점이 있을까요? 마나 검증 로직을 한 곳에서 관리할 수 있지 않을까요?

2. 중복 코드 제거

  • Wizard와 GreatWizard의 heal() 메서드 구조가 유사합니다:
    • 마나 체크 → 마나 소비 → HP 증가 → 메시지 출력
  • 질문: "마나 부족 메시지 출력"이나 "마나 체크" 같은 공통 부분을 어느 클래스에 배치하면 코드 중복을 줄일 수 있을까요?

3. 메서드 이름 관례

  • SuperHeal() 메서드 이름이 파스칼 케이스(PascalCase)를 따르고 있습니다.
  • 질문: Java의 메서드 명명 관례(Naming Convention)를 다시 확인해 본다면, SuperHeal() 대신 어떤 이름이 더 적절할까요? (예: superHeal())

4. 책임 분리 (Single Responsibility)

  • 현재 heal() 메서드가 "마나 체크" + "HP 증가" + "출력" 세 가지를 모두 처리하고 있습니다.
  • 질문: "HP 증가" 로직을 따로 메서드로 추출한다면, heal() 메서드의 가독성과 유지보수성이 더 좋아지지 않을까요?

📝 제출 완성도

✅ 모든 JUnit 테스트 통과
✅ 상속과 오버라이딩 개념 이해
✅ 캡슐화 기본 원칙 적용
✅ 코드 포매팅 완료

학생이 OOP의 핵심 개념을 잘 이해하고 있으며, 위의 개선 사항들을 반영한다면 더욱 견고한 코드가 될 수 있습니다. 좋은 첫 단계입니다! 🚀

Walkthrough

Hero 클래스를 캡슐화하여 private 필드와 public API(incrementHP, getter 등)를 추가하고, WizardGreatWizard 상속 계층을 새로 구현한다. 각 클래스의 heal/SuperHeal 동작을 JUnit5 테스트로 검증하며, 상속·오버라이딩 학습 내용을 담은 TIL 문서도 함께 추가된다.

Changes

게임 클래스 계층 구현 및 테스트

Layer / File(s) Summary
Hero 기반 클래스 캡슐화 및 공개 API 추가
game/src/main/java/com/survivalcoding/Hero.java
name, hp 필드를 private으로 변경하고 maxhp 필드를 추가한다. 생성자, incrementHP(maxhp 초과 시 고정 로직 포함), getName/getHp/getMaxhp getter를 public API로 추가한다.
Wizard·GreatWizard 상속 계층 및 heal 메서드
game/src/main/java/com/survivalcoding/Wizard.java, game/src/main/java/com/survivalcoding/GreatWizard.java
WizardHero를 상속하며 mp/maxmpheal(mp≥10 소모, HP+20)을 구현한다. GreatWizardWizard를 상속하여 heal을 오버라이드(mp≥5 소모, HP+25)하고, SuperHeal(mp≥50 소모, HP+maxhp)을 추가한다.
JUnit5 heal/SuperHeal 시나리오 테스트
game/src/test/java/com/survivalcoding/gametest.java
BeforeEach에서 Hero/Wizard/GreatWizard 인스턴스를 초기화하고, 일반 힐·슈퍼 힐·마나 부족 시 HP 불변·HP의 MaxHP 초과 불가 시나리오를 assertEquals로 검증한다.

TIL 학습 문서

Layer / File(s) Summary
상속 TIL 문서 추가
TIL/sample/2026-06-16-상속.md
Java extends/@Override와 C++ virtual 키워드의 정적/동적 바인딩 차이, JUnit5 실습 테스트 시나리오, vtable 개념 이해 및 IntelliJ Gradle Runner 설정 변경 해결 방법을 섹션별로 정리한다.

Sequence Diagram(s)

sequenceDiagram
  participant GameTest
  participant Wizard
  participant GreatWizard
  participant Hero

  rect rgba(100, 149, 237, 0.5)
    Note over GameTest,Hero: 일반 힐 (Wizard.heal)
    GameTest->>Wizard: heal(hero)
    Wizard->>Hero: incrementHP(20)
    Hero-->>Wizard: hp = min(hp+20, maxhp)
  end

  rect rgba(144, 238, 144, 0.5)
    Note over GameTest,Hero: 슈퍼 힐 (GreatWizard.SuperHeal)
    GameTest->>GreatWizard: SuperHeal(hero)
    GreatWizard->>Hero: getMaxhp()
    Hero-->>GreatWizard: maxhp
    GreatWizard->>Hero: incrementHP(maxhp)
    Hero-->>GreatWizard: hp = min(hp+maxhp, maxhp)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive PR 제목이 너무 모호하고 구체적인 정보를 포함하지 않습니다. '260616_11_유재우'는 단순한 타임스탬프와 학생명이며, 실제 변경 사항을 나타내지 않습니다. PR 제목을 '상속 및 오버라이딩 구현: Hero, Wizard, GreatWizard 클래스 추가' 와 같이 변경하여 주요 변경 사항을 명확히 표현해주세요.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed PR 설명이 템플릿의 모든 필수 섹션(과제 정보, 체크리스트, 실행 결과, 어려웠던 점, 자체 평가)을 포함하고 있으며, 스크린샷과 UML 다이어그램으로 구현 내용을 명확히 문서화하고 있습니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
game/src/test/java/com/survivalcoding/gametest.java (1)

22-46: ⚡ Quick win

테스트 설명의 계약(마나 소모/비소모)을 assert로 실제 검증해 주세요.

현재 테스트명은 MP 변화를 명시하지만 HP만 검증하고 있습니다. MP assert를 추가하면 회귀 탐지가 훨씬 정확해집니다.

제안 수정안
     void wizardHealTest() {
         wizard.heal(targetHero);

         assertEquals(70, targetHero.getHp(), "전사의 HP는 50에서 20이 더해져 70이 되어야 합니다.");
+        assertEquals(20, wizard.mp, "힐 후 마나는 30에서 10 소모되어 20이어야 합니다.");
     }
@@
     void greatWizardSuperHealTest() {
         greatWizard.SuperHeal(targetHero);

         assertEquals(100, targetHero.getHp(), "슈퍼 힐을 받으면 최대 체력인 100이 되어야 합니다.");
+        assertEquals(10, greatWizard.mp, "슈퍼 힐 후 마나는 60에서 50 소모되어 10이어야 합니다.");
     }
@@
     void outOfManaTest() {
         Wizard oomWizard = new Wizard("마나없는법사", 50, 50, 5, 50);

         oomWizard.heal(targetHero);

         assertEquals(50, targetHero.getHp(), "마나가 부족하므로 타겟의 HP는 변하면 안 됩니다.");
+        assertEquals(5, oomWizard.mp, "마나 부족 시 마나는 소모되면 안 됩니다.");
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@game/src/test/java/com/survivalcoding/gametest.java` around lines 22 - 46,
The test methods wizardHealTest, greatWizardSuperHealTest, and outOfManaTest
have names that describe expected mana consumption, but they only assert HP
changes and do not verify the mana (MP) values. Add assertEquals assertions for
the expected mana values after each spell cast to match the contract described
in the test display names: wizardHealTest should verify mana decreased by 10,
greatWizardSuperHealTest should verify mana decreased by 50, and outOfManaTest
should verify mana remained unchanged when insufficient.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@game/src/main/java/com/survivalcoding/Hero.java`:
- Around line 8-12: The Hero constructor does not validate the HP invariant that
requires 0 <= hp <= maxhp. Add validation logic in the Hero constructor to
ensure the hp parameter is within the valid range before assignment. If hp is
negative, clamp it to 0; if hp exceeds maxhp, clamp it to maxhp. This ensures
the object maintains its invariant from creation and aligns with the upper bound
correction logic used elsewhere like incrementHP.

In `@TIL/sample/2026-06-16-상속.md`:
- Around line 183-190: The fenced code block in the document lacks a language
identifier after the opening triple backticks, which triggers a markdownlint
warning. Add a language tag such as `text` immediately after the opening code
fence (the ```) on line 183 to specify the code block language and resolve the
linting error.

---

Nitpick comments:
In `@game/src/test/java/com/survivalcoding/gametest.java`:
- Around line 22-46: The test methods wizardHealTest, greatWizardSuperHealTest,
and outOfManaTest have names that describe expected mana consumption, but they
only assert HP changes and do not verify the mana (MP) values. Add assertEquals
assertions for the expected mana values after each spell cast to match the
contract described in the test display names: wizardHealTest should verify mana
decreased by 10, greatWizardSuperHealTest should verify mana decreased by 50,
and outOfManaTest should verify mana remained unchanged when insufficient.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6c36b170-5453-405c-83af-68f44ec14980

📥 Commits

Reviewing files that changed from the base of the PR and between 5f57054 and 999c8bb.

📒 Files selected for processing (5)
  • TIL/sample/2026-06-16-상속.md
  • game/src/main/java/com/survivalcoding/GreatWizard.java
  • game/src/main/java/com/survivalcoding/Hero.java
  • game/src/main/java/com/survivalcoding/Wizard.java
  • game/src/test/java/com/survivalcoding/gametest.java

Comment on lines +8 to 12
public Hero(String name, int hp, int maxhp) {
this.name = name;
this.hp = hp;
this.maxhp = maxhp;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

생성자에서 HP 불변식(0 <= hp <= maxhp)이 보장되지 않습니다.

현재는 생성 시 hp > maxhp 또는 음수 값이 그대로 들어갈 수 있어 객체가 즉시 비정상 상태가 됩니다. incrementHP의 상한 보정 계약과도 어긋납니다.

제안 수정안
 public Hero(String name, int hp, int maxhp) {
-    this.name = name;
-    this.hp = hp;
-    this.maxhp = maxhp;
+    if (hp < 0 || maxhp < 0) {
+        throw new IllegalArgumentException("hp와 maxhp는 0 이상이어야 합니다.");
+    }
+    this.name = name;
+    this.maxhp = maxhp;
+    this.hp = Math.min(hp, maxhp);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public Hero(String name, int hp, int maxhp) {
this.name = name;
this.hp = hp;
this.maxhp = maxhp;
}
public Hero(String name, int hp, int maxhp) {
if (hp < 0 || maxhp < 0) {
throw new IllegalArgumentException("hp와 maxhp는 0 이상이어야 합니다.");
}
this.name = name;
this.maxhp = maxhp;
this.hp = Math.min(hp, maxhp);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@game/src/main/java/com/survivalcoding/Hero.java` around lines 8 - 12, The
Hero constructor does not validate the HP invariant that requires 0 <= hp <=
maxhp. Add validation logic in the Hero constructor to ensure the hp parameter
is within the valid range before assignment. If hp is negative, clamp it to 0;
if hp exceeds maxhp, clamp it to maxhp. This ensures the object maintains its
invariant from creation and aligns with the upper bound correction logic used
elsewhere like incrementHP.

Comment on lines +183 to +190
```
설정
└─ 빌드, 실행, 배포
└─ 빌드 도구
└─ Gradle
└─ 다음을 사용하여 테스트 실행
Gradle → IntelliJ IDEA
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

코드 블록 언어를 지정해 주세요.

183행의 fenced code block에 언어 태그가 없어 markdownlint 경고가 납니다. text 같은 언어를 붙이거나, 코드 펜스를 제거하면 됩니다.

🛠️ 제안 수정
-```
+```text
 설정
 └─ 빌드, 실행, 배포
 └─ 빌드 도구
 └─ Gradle
 └─ 다음을 사용하여 테스트 실행
 Gradle → IntelliJ IDEA
-```
+```
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)

[warning] 183-183: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@TIL/sample/2026-06-16-상속.md` around lines 183 - 190, The fenced code block in
the document lacks a language identifier after the opening triple backticks,
which triggers a markdownlint warning. Add a language tag such as `text`
immediately after the opening code fence (the ```) on line 183 to specify the
code block language and resolve the linting error.

Source: Linters/SAST tools

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.

1 participant