Skip to content

260616_20_이종재#51

Open
jongjae0305 wants to merge 2 commits into
SurvivalCodingCampus:student/20_이종재from
jongjae0305:main
Open

260616_20_이종재#51
jongjae0305 wants to merge 2 commits into
SurvivalCodingCampus:student/20_이종재from
jongjae0305:main

Conversation

@jongjae0305

Copy link
Copy Markdown

260616_20_이종재

📝 과제 정보

  • 교육 주제: 오버라이딩

📋 체크리스트

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

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

image

❓질문 및 어려웠던 점

  • 자식 클래스에서 부모 클래스의 필드를 또 만들면 값이 따로 관리될 수 있다는 점이 헷갈렸다.
  • 예를 들어 부모에도 mp가 있고 자식에도 mp가 있으면 getMp()this.mp가 서로 다른 값을 볼 수 있다.

🔄 자체 평가 & 회고

  • 오버로딩과 오버라이딩의 차이점을 다시 한번 확인하였으며 특히 중복된 변수가 있는경우 서로 다른 값을 볼수있다는것을 확인할수 있었다

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

메서드 오버라이딩 과제 검토 및 피드백

전반적 평가

축하합니다! 이번 과제에서는 상속(Inheritance), 메서드 오버라이딩(Method Overriding), **다형성(Polymorphism)**의 핵심 개념을 잘 이해하고 구현했습니다. 모든 JUnit 테스트가 통과했으며, 코드 구조도 명확합니다.


잘 구현된 부분

1. 상속 구조의 명확성

  • Wizard를 추상 클래스로 정의하고, GreatWizard가 이를 상속받아 특화된 기능을 추가한 점이 좋습니다.
  • HeroSuperHero, SlimePoisonSlime의 관계도 적절하게 설계되었습니다.

2. 메서드 오버라이딩의 올바른 사용

  • GreatWizard.heal()SuperHero.attack(), PoisonSlime.attack()에서 @Override 어노테이션을 명시했습니다.
  • super.attack()이나 super(name, hp) 같이 부모 기능을 활용한 후 기능을 확장하는 패턴이 적절합니다.

3. 캡슐화 적용

  • getHp(), setHp() 같은 getter/setter를 활용하여 필드를 보호하고 있습니다.
  • WizardsetMp()에서 유효성 검사(mp < 0 시 예외 발생)를 구현한 점이 훌륭합니다.

4. 테스트 코드의 품질

  • GreatWizardTestPoisonSlimeTest에서 상수를 활용하여 테스트 값을 관리하고, 다양한 시나리오(정상 케이스, 부족한 MP 케이스 등)를 검증했습니다.

개선 제안 (Socratic 피드백)

1. Slime 클래스의 접근 제어자 검토

질문: Slime.attack() 메서드가 현재 package-private로 선언되어 있습니다. 자식 클래스 PoisonSlime에서 이를 오버라이드할 때, 접근 제어자를 명시적으로 선언했나요?

힌트: 오버라이딩할 때 자식 클래스 메서드의 접근 제어자는 부모보다 더 제한적이지 않아야 합니다. 현재 코드에서는 문제가 없지만, 의도를 명확히 하려면 어떻게 해야 할까요?


2. Hero 클래스의 필드 초기화 재검토

질문: 현재 Hero 클래스에서 maxHP는 고정값(150)이고, hp는 기본값(100)입니다. 그런데 생성자에서 hp를 설정할 때, maxHP도 함께 설정할 수 있어야 하지 않을까요?

힌트: 어떤 경우에는 최대 HP가 달라질 수도 있습니다. 현재 설계에서 이런 유연성이 필요한지, 아니면 maxHP를 final 필드로 더 엄격하게 관리해야 하는지 생각해보세요.


3. PoisonSlime.attack() 메서드의 로직 단순화

질문: 현재 코드에서:

if(this.poisonCount > 0){
    // ... 독 포자 처리
}

이 조건은 독을 한 번만 적용한다는 의미입니다. 그렇다면 poisonCount 필드가 왜 필요할까요?

힌트: 이 필드의 목적이 무엇인지, 그리고 현재 로직이 그 목적을 제대로 반영하고 있는지 다시 생각해보세요. 만약 독을 여러 번 적용해야 한다면 어떻게 설계해야 할까요?


4. WizardGreatWizard의 필드 분리

과제에서 언급한 내용: 부모와 자식이 같은 이름의 필드를 선언할 때 독립적으로 관리된다는 점을 확인하셨습니다.

질문: 현재 코드에서 Wizardmp 필드는 protected나 public으로 선언되지 않았습니다. GreatWizard에서 부모의 mp를 직접 접근하지 않고 getMp(), setMp()를 통해 접근하고 있습니다. 이것이 좋은 캡슐화인 이유가 무엇일까요?


5. 코드 컨벤션 제안

  • Hero 클래스의 필드 선언 순서를 재정렬하면 더 가독성이 좋을까요? (예: 관련 필드끼리 그룹화)
  • 일부 메서드에서 불필요한 else 블록을 제거하면 더 간단해질 수 있습니다. 예를 들어:
    if (getMp() < 5) {
        System.out.println("마나가 부족합니다");
        return;
    }
    // 여기서는 이미 마나가 충분함이 보장됨

다음 학습 단계

  1. 추상 메서드(Abstract Method) 활용: Wizard를 더 추상화하여 자식 클래스가 반드시 구현해야 할 메서드를 정의할 수 있습니다.
  2. 인터페이스(Interface): 공통 행동을 정의하고 여러 클래스가 구현하도록 강제할 수 있습니다.
  3. 동적 바인딩: Wizard 타입의 변수에 GreatWizard 인스턴스를 할당하여 다형성을 더 활용해보세요.

축하합니다! OOP의 핵심 개념을 잘 이해하고 있습니다. 위의 질문들을 통해 코드를 더욱 개선해보세요! 🎓

Walkthrough

day260608/day260609 Cleric 클래스의 접근 제어자를 public으로 확장하고, day260615 소스·테스트 파일 전체의 package 선언을 하위 패키지로 이동한다. day260616에는 Hero/Slime/Wizard 기반 클래스와 SuperHero/PoisonSlime/GreatWizard 서브클래스 계층을 새로 추가하며, 이를 검증하는 JUnit 테스트와 TIL 학습 노트 두 편이 포함된다.

Changes

기존 코드 패키지 정리 및 가시성 수정

Layer / File(s) Summary
day260608/day260609 Cleric 가시성 변경
day01-basic/src/main/java/com/survivalcoding/day260608/Cleric.java, day01-basic/src/main/java/com/survivalcoding/day260609/Cleric.java
day260608 Cleric의 hp/mp/name 필드 및 selfAid/pray 메서드, day260609 Cleric의 maxHp/maxMp 상수·필드·생성자 세 개를 package-private에서 public으로 변경한다.
day260615 소스 파일 패키지 선언 일괄 수정
day01-basic/src/main/java/com/survivalcoding/day260615/*.java, day01-basic/src/main/java/com/survivalcoding/day260615/game/build.gradle, settings.gradle
day260615 디렉터리 내 13개 클래스 파일의 package 선언을 com.survivalcoding에서 com.survivalcoding.day260615로 변경하고, 잘못된 위치의 build.gradle 내용을 삭제하며 settings.gradle에서 game 모듈 포함을 제거한다.
테스트 패키지 선언 수정 및 단언값 교정
day01-basic/src/test/java/com/survivalcoding/MainTest.java, day01-basic/src/test/java/com/survivalcoding/day260608/ClericTest.java, day01-basic/src/test/java/com/survivalcoding/day260609/MainTest.java, day01-basic/src/test/java/com/survivalcoding/day260615/*.java, TIL/sample/2026-06-15.md
day260608/day260609 테스트의 중첩 패키지 오류를 수정하고, day260615 테스트 5개 파일을 올바른 패키지로 이동한다. ClericTest의 name 기대값을 수정하고, 최상위 MainTest를 제거하며, TIL 2026-06-15 노트를 추가한다.

day260616 상속·오버라이딩·다형성 예제 신규 구현

Layer / File(s) Summary
Hero·Slime·Wizard 기반 클래스 정의
day01-basic/src/main/java/com/survivalcoding/day260616/Hero.java, day01-basic/src/main/java/com/survivalcoding/day260616/Slime.java, day01-basic/src/main/java/com/survivalcoding/day260616/Wizard.java
Hero(이름/체력/행동 메서드), Slime(이름/체력/attack), Wizard 추상 클래스(MP 검증·heal 로직)를 새로 추가한다.
SuperHero·PoisonSlime·GreatWizard 서브클래스 및 Main
day01-basic/src/main/java/com/survivalcoding/day260616/SuperHero.java, day01-basic/src/main/java/com/survivalcoding/day260616/PoisonSlime.java, day01-basic/src/main/java/com/survivalcoding/day260616/GreatWizard.java, day01-basic/src/main/java/com/survivalcoding/day260616/Main.java
SuperHero는 isFlying 상태에 따라 run/attack을 오버라이드하고, PoisonSlime은 super.attack 후 poisonCount만큼 독 데미지를 추가 적용하며, GreatWizard는 heal을 오버라이드하고 superHeal을 추가한다. Main에서 Hero·SuperHero를 생성해 run()을 호출한다.
GreatWizardTest·PoisonSlimeTest 및 TIL 2026-06-16
day01-basic/src/test/java/com/survivalcoding/day260616/GreatWizardTest.java, day01-basic/src/test/java/com/survivalcoding/day260616/PoisonSlimeTest.java, TIL/sample/2026-06-16.md
GreatWizardTest는 heal/superHeal의 HP 회복·MP 소비와 MP 부족 시 무변화를 4개 테스트로 검증하고, PoisonSlimeTest는 일반 공격과 독 데미지 합산 결과를 검증한다. TIL 2026-06-16 노트가 추가된다.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning PR 제목이 실제 변경 사항과 일치하지 않습니다. 제목은 '260616_20_이종재'로 학생 ID와 이름만 포함하고 있으며, 오버라이딩에 대한 실질적 변경 내용을 반영하지 못합니다. PR 제목을 변경하여 주요 변경사항을 명확하게 반영해야 합니다. 예: '오버라이딩 과제: GreatWizard, SuperHero, PoisonSlime 클래스 추가' 또는 유사한 형식으로 수정하세요.
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.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed PR 설명이 제공된 템플릿 구조를 따르고 있으며, 과제 정보(오버라이딩), 체크리스트 항목 완료, 실행 결과 이미지, 어려웠던 점, 자체 평가를 모두 포함하고 있습니다.
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: 3

🤖 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 `@day01-basic/src/main/java/com/survivalcoding/day260616/Hero.java`:
- Around line 12-15: The attack method in the Hero class is incorrectly reducing
the attacker's own HP instead of the target Slime's HP. In the attack(Slime
slime) method body, change the line that currently decreases hp to instead
decrease the slime parameter's HP. This will ensure the attack damages the
intended target (the Slime) rather than harming the attacker, which will also
fix the inherited behavior in SuperHero.attack that calls super.attack(slime).

In `@day01-basic/src/main/java/com/survivalcoding/day260616/SuperHero.java`:
- Line 28: There is a typo in the output string within the SuperHero class where
"입혔따" should be corrected to "입혔다". Locate the System.out.println statement that
outputs the 5-point damage message and fix the typo by replacing the incorrect
Korean character sequence with the correct spelling. This is a user-facing
message so the correction is important for clarity.

In `@TIL/sample/2026-06-16.md`:
- Around line 133-136: The GreatWizard constructor example in the documentation
uses setMp(150) but the actual implementation uses super(150). Update the
constructor example in the GreatWizard class to use super(150) instead of
setMp(150) to align the documentation with the actual implementation and
maintain consistency in demonstrating inheritance constructor chaining patterns.
🪄 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: 527bdc8a-be71-4b6e-b6f1-23e9ebdd4b21

📥 Commits

Reviewing files that changed from the base of the PR and between 164db2a and c559db6.

📒 Files selected for processing (36)
  • TIL/sample/2026-06-15.md
  • TIL/sample/2026-06-16.md
  • day01-basic/src/main/java/com/survivalcoding/day260608/Cleric.java
  • day01-basic/src/main/java/com/survivalcoding/day260609/Cleric.java
  • day01-basic/src/main/java/com/survivalcoding/day260615/Cleric.java
  • day01-basic/src/main/java/com/survivalcoding/day260615/EncapsulationExam.java
  • day01-basic/src/main/java/com/survivalcoding/day260615/GameConfig.java
  • day01-basic/src/main/java/com/survivalcoding/day260615/Hero.java
  • day01-basic/src/main/java/com/survivalcoding/day260615/Inn.java
  • day01-basic/src/main/java/com/survivalcoding/day260615/King.java
  • day01-basic/src/main/java/com/survivalcoding/day260615/Kinoko.java
  • day01-basic/src/main/java/com/survivalcoding/day260615/Main.java
  • day01-basic/src/main/java/com/survivalcoding/day260615/Person.java
  • day01-basic/src/main/java/com/survivalcoding/day260615/Quiz.java
  • day01-basic/src/main/java/com/survivalcoding/day260615/Sword.java
  • day01-basic/src/main/java/com/survivalcoding/day260615/Wand.java
  • day01-basic/src/main/java/com/survivalcoding/day260615/Wizard.java
  • day01-basic/src/main/java/com/survivalcoding/day260615/game/build.gradle
  • day01-basic/src/main/java/com/survivalcoding/day260616/GreatWizard.java
  • day01-basic/src/main/java/com/survivalcoding/day260616/Hero.java
  • day01-basic/src/main/java/com/survivalcoding/day260616/Main.java
  • day01-basic/src/main/java/com/survivalcoding/day260616/PoisonSlime.java
  • day01-basic/src/main/java/com/survivalcoding/day260616/Slime.java
  • day01-basic/src/main/java/com/survivalcoding/day260616/SuperHero.java
  • day01-basic/src/main/java/com/survivalcoding/day260616/Wizard.java
  • day01-basic/src/test/java/com/survivalcoding/MainTest.java
  • day01-basic/src/test/java/com/survivalcoding/day260608/ClericTest.java
  • day01-basic/src/test/java/com/survivalcoding/day260609/MainTest.java
  • day01-basic/src/test/java/com/survivalcoding/day260615/ClericTest.java
  • day01-basic/src/test/java/com/survivalcoding/day260615/HeroTest.java
  • day01-basic/src/test/java/com/survivalcoding/day260615/PersonTest.java
  • day01-basic/src/test/java/com/survivalcoding/day260615/WandTest.java
  • day01-basic/src/test/java/com/survivalcoding/day260615/WizardTest.java
  • day01-basic/src/test/java/com/survivalcoding/day260616/GreatWizardTest.java
  • day01-basic/src/test/java/com/survivalcoding/day260616/PoisonSlimeTest.java
  • settings.gradle
💤 Files with no reviewable changes (2)
  • day01-basic/src/main/java/com/survivalcoding/day260615/game/build.gradle
  • day01-basic/src/test/java/com/survivalcoding/MainTest.java

Comment on lines +12 to +15
public void attack(Slime slime){
System.out.println(name + "이 공격했다.");
hp -= 10;
}

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

기본 공격 대상이 잘못되었습니다.

Line 14에서 공격자가 자신의 HP를 감소시키고 있어, attack(Slime slime)의 기본 계약(대상에게 피해)이 깨집니다. 이 루트 문제 때문에 SuperHero.attacksuper.attack(slime)도 의도한 일반 피해를 보장하지 못합니다.

제안 수정안
 public void attack(Slime slime){
     System.out.println(name + "이 공격했다.");
-    hp -= 10;
+    slime.setHp(slime.getHp() - 10);
 }
🤖 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 `@day01-basic/src/main/java/com/survivalcoding/day260616/Hero.java` around
lines 12 - 15, The attack method in the Hero class is incorrectly reducing the
attacker's own HP instead of the target Slime's HP. In the attack(Slime slime)
method body, change the line that currently decreases hp to instead decrease the
slime parameter's HP. This will ensure the attack damages the intended target
(the Slime) rather than harming the attacker, which will also fix the inherited
behavior in SuperHero.attack that calls super.attack(slime).

super.attack(slime);
if(isFlying){
slime.setHp(slime.getHp() - 5);
System.out.println("5포인트의 추가 피해를 입혔따");

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

출력 문자열 오타를 수정해 주세요.

Line 28 "입혔따""입혔다" 오타입니다. 사용자에게 노출되는 메시지라 정정하는 편이 좋습니다.

-            System.out.println("5포인트의 추가 피해를 입혔따");
+            System.out.println("5포인트의 추가 피해를 입혔다");
🤖 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 `@day01-basic/src/main/java/com/survivalcoding/day260616/SuperHero.java` at
line 28, There is a typo in the output string within the SuperHero class where
"입혔따" should be corrected to "입혔다". Locate the System.out.println statement that
outputs the 5-point damage message and fix the typo by replacing the incorrect
Korean character sequence with the correct spelling. This is a user-facing
message so the correction is important for clarity.

Comment thread TIL/sample/2026-06-16.md
Comment on lines +133 to +136
public class GreatWizard extends Wizard {
public GreatWizard() {
setMp(150);
}

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

실습 코드 예시가 실제 구현과 달라 학습 포인트를 혼동시킬 수 있습니다.

GreatWizard 생성자 예시가 실제 코드(super(150))와 달라서, 상속 생성자 체이닝 학습 맥락이 어긋납니다. 문서 예시를 실제 구현과 맞춰 주세요.

문서 예시 정합성 수정안
 public class GreatWizard extends Wizard {
     public GreatWizard() {
-        setMp(150);
+        super(150);
     }
📝 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 class GreatWizard extends Wizard {
public GreatWizard() {
setMp(150);
}
public class GreatWizard extends Wizard {
public GreatWizard() {
super(150);
}
🤖 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 133 - 136, The GreatWizard constructor
example in the documentation uses setMp(150) but the actual implementation uses
super(150). Update the constructor example in the GreatWizard class to use
super(150) instead of setMp(150) to align the documentation with the actual
implementation and maintain consistency in demonstrating inheritance constructor
chaining patterns.

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