Skip to content

260616_17_서인호#59

Open
cornaill008 wants to merge 3 commits into
SurvivalCodingCampus:student/17_서인호from
cornaill008:master
Open

260616_17_서인호#59
cornaill008 wants to merge 3 commits into
SurvivalCodingCampus:student/17_서인호from
cornaill008:master

Conversation

@cornaill008

Copy link
Copy Markdown

260616_17_서인호

📝 과제 정보

  • 상속
  • 생성자
  • 부모클래스, 자식클래스

📋 체크리스트

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

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

❓질문 및 어려웠던 점

🔄 자체 평가 & 회고

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

코드 리뷰 피드백

🎯 긍정적인 측면

1. 상속(Inheritance) 구현

  • GreatWizardPoisonSlime 클래스에서 부모 클래스를 올바르게 상속하고, 생성자에서 super() 또는 상위 클래스의 메서드를 호출하는 방식이 좋습니다.
  • GreatWizard에서 부모 클래스의 필드를 getters/setters로 접근하는 방식은 캡슐화 원칙을 잘 따르고 있습니다.

2. 다형성(Polymorphism) 활용

  • heal() 메서드 오버라이드 (WizardGreatWizard)
  • attack() 메서드 오버라이드 (SlimePoisonSlime)
  • @Override 어노테이션을 사용하여 의도를 명확히 하고 있습니다. ✓

3. 메서드 설계

  • superHeal()attack() 메서드에서 MP/poisonCount와 같은 자원을 체크한 후 소비하는 로직이 좋습니다.

⚠️ 검토가 필요한 사항

1. Hero 클래스와의 인터페이스 불일치 - 중요

현재 Wizard, GreatWizard, Slime, PoisonSlime 클래스들이 다음과 같이 호출하고 있습니다:

hero.getHp()
hero.setHp(...)

그러나 제공하신 Hero 클래스를 보면 이 메서드들이 정의되어 있지 않습니다.

질문:

  • Hero 클래스에 getHp()setHp() 메서드가 있어야 하지 않을까요?
  • Hero 클래스의 hp 필드에 직접 접근하지 않고 메서드를 통해 접근하려고 했을까요? (힌트: 캡슐화)

2. Slime 클래스의 접근성(Visibility)

void attack(Hero hero) { ... }  // 접근자가 명시되지 않음

질문:

  • 현재 attack() 메서드에 접근자(public, private 등)가 명시되지 않았습니다.
  • 다른 패키지의 코드에서도 이 메서드를 호출할 수 있어야 할까요?
  • Wizard 클래스의 메서드들이 public인 이유는 무엇일까요?

3. Hero 클래스의 캡슐화

public Hero {
    String name;    // package-private
    int hp;         // package-private
}

질문:

  • 다른 클래스에서 Hero의 필드를 직접 수정할 수 있다는 뜻입니다.
  • 데이터를 보호하기 위해 어떻게 해야 할까요?
  • Wizard 클래스에서 private 필드와 public getters/setters를 사용한 이유는 무엇일까요?

📋 제안

  1. 컴파일 확인: Hero 클래스에 getHp(), setHp() 메서드가 필요합니다. 먼저 이 메서드들을 구현한 후 JUnit 테스트를 실행해 보세요.

  2. 메서드 접근성 점검: 각 메서드가 public, protected, package-private 중 어느 것이어야 하는지 생각해 보세요. 외부에서 접근 가능해야 하는가?

  3. 일관성: Wizard 클래스의 데이터 보호 방식을 Hero 클래스에도 적용해 보세요.


체크리스트

  • ✓ 상속과 생성자 개념 이해
  • ✓ 메서드 오버라이딩 구현
  • ⚠️ Hero 클래스 getters/setters 구현 필요
  • ⚠️ 메서드 접근성(visibility) 검토 필요
  • ⚠️ 모든 JUnit 테스트 통과 확인 필요

Walkthrough

Wizard 클래스에 필드·접근자·heal·fireball 스텁을 추가하고, 이를 상속하는 GreatWizard에 오버라이드된 healsuperHeal을 구현했다. 또한 Slime 베이스 클래스와 독 공격 로직을 가진 PoisonSlime 서브클래스, 그리고 주석만 포함된 연습문제 스켈레톤 파일을 추가했다.

Changes

OOP 상속 기반 캐릭터 클래스 구현

Layer / File(s) Summary
Wizard 베이스 및 GreatWizard 서브클래스
day02-instance-class/.../Wizard.java, day02-instance-class/.../GreatWizard.java
Wizardhp/mp/name/wand 필드와 검증 포함 게터/세터, heal(MP 비용 10), 빈 fireball을 추가. GreatWizardWizard 상속 후 초기 MP 150, heal 오버라이드(MP 비용 5, HP +25), superHeal(MP 비용 50, HP 100 고정 세트)을 구현.
Slime 베이스 및 PoisonSlime 서브클래스
day02-instance-class/.../Slime.java, day02-instance-class/.../PoisonSlime.java
Slimesuffix/hp 필드와 attack(HP −10)을 구현. PoisonSlimeSlime 상속 후 poisonCount(초기 5) 잔여 시 super.attack 실행 후 현재 HP의 1/5 추가 독 데미지를 적용하고 카운트를 차감.
연습문제 스켈레톤
day02-instance-class/.../연습문제_1.java
구현 없이 연습문제 설명 주석만 포함하는 공개 클래스 스켈레톤 파일 추가.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (1 warning, 2 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% 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_17_서인호'로 매우 모호하며, 실제 변경사항을 설명하지 않습니다. PR 제목을 '상속과 생성자 개념을 적용한 마법사, 슬라임 클래스 구현' 같이 구체적으로 변경하여 주요 변경사항을 명확히 하세요.
Description check ❓ Inconclusive 필수 섹션이 있지만 실행 결과, 질문/어려웠던 점, 자체 평가 항목이 비어있습니다. 실행 결과, 질문/어려웠던 점, 자체 평가 섹션을 채워 PR 설명을 완성하세요.
✅ Passed checks (2 passed)
Check name Status Explanation
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.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PMD (7.25.0)
day02-instance-class/src/main/java/com/survivalcoding/연습문제_1.java

Invalid value for option '--dir' at index 0 (): cannot convert 'day02-instance-class/src/main/java/com/survivalcoding/????????????_1.java' to interface java.nio.file.Path (java.nio.file.InvalidPathException: Malformed input or input contains unmappable characters: day02-instance-class/src/main/java/com/survivalcoding/????????????_1.java)
Usage: pmd check [-bDh] [--no-cache] [--[no-]fail-on-error] [--[no-]
fail-on-violation] [--[no-]progress] [--show-suppressed]
[--aux-classpath=] [--cache=]
[-f=] [--force-language=]
[--minimum-priority=] [-r=]
[--suppress-marker=] [-t=]
[-P=<String=String>]... [--use-version=]...
-R=[,...]... [-R=[,
...]...]... [[-e=]
[-

... [truncated 14426 characters] ...

    --file-list or --uri must be provided.

-z, --relativize-paths-with=[,
...]...
Path relative to which directories are rendered in
the report. This option allows shortening
directories in the report; without it, paths are
rendered as mentioned in the source directory
(option "--dir"). The option can be repeated, in
which case the shortest relative path will be
used. If the root path is mentioned (e.g. "/" or
"C:"), then the paths will be rendered as
absolute.


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: 1

🤖 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 `@day02-instance-class/src/main/java/com/survivalcoding/Wizard.java`:
- Around line 51-60: Add null validation for the hero parameter at the beginning
of each method to prevent NullPointerException. In
day02-instance-class/src/main/java/com/survivalcoding/Wizard.java lines 51-60,
add a null check for the hero parameter at the start of the heal method before
any logic executes. Apply the same null validation pattern to
day02-instance-class/src/main/java/com/survivalcoding/GreatWizard.java lines
9-17 in the heal method override and lines 19-27 in the superHeal method.
Additionally, add null validation in
day02-instance-class/src/main/java/com/survivalcoding/Slime.java lines 15-20 at
the start of the attack method to protect the base method that is called by
subclasses. Each null check should return early or print an appropriate error
message if the hero parameter is null.
🪄 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: 82d49938-db87-4a35-9e1c-004d2a0287f8

📥 Commits

Reviewing files that changed from the base of the PR and between 4e055d7 and c267d25.

📒 Files selected for processing (5)
  • day02-instance-class/src/main/java/com/survivalcoding/GreatWizard.java
  • day02-instance-class/src/main/java/com/survivalcoding/PoisonSlime.java
  • day02-instance-class/src/main/java/com/survivalcoding/Slime.java
  • day02-instance-class/src/main/java/com/survivalcoding/Wizard.java
  • day02-instance-class/src/main/java/com/survivalcoding/연습문제_1.java

Comment on lines +51 to +60
public void heal(Hero hero) {
if (mp < 10) {
System.out.println("마나가 부족합니다");
return;
}

hero.setHp(hero.getHp() + 20);
mp -= 10;
System.out.println("힐을 시전했습니다. 대상 HP: " + hero.getHp());
}

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

공통 원인: 전투/치유 API의 대상 파라미터 null 경계 검증이 빠져 있습니다.

  • day02-instance-class/src/main/java/com/survivalcoding/Wizard.java#L51-L60: heal(Hero hero) 시작 지점에 null 검증을 추가하세요.
  • day02-instance-class/src/main/java/com/survivalcoding/GreatWizard.java#L9-L17: heal(Hero hero)에 동일한 null 검증(또는 공통 헬퍼)을 적용하세요.
  • day02-instance-class/src/main/java/com/survivalcoding/GreatWizard.java#L19-L27: superHeal(Hero hero)에도 동일한 검증을 적용하세요.
  • day02-instance-class/src/main/java/com/survivalcoding/Slime.java#L15-L20: attack(Hero hero) 베이스 메서드에서 null 검증을 추가해 하위 클래스 호출 경로까지 보호하세요.
📍 Affects 3 files
  • day02-instance-class/src/main/java/com/survivalcoding/Wizard.java#L51-L60 (this comment)
  • day02-instance-class/src/main/java/com/survivalcoding/GreatWizard.java#L9-L17
  • day02-instance-class/src/main/java/com/survivalcoding/GreatWizard.java#L19-L27
  • day02-instance-class/src/main/java/com/survivalcoding/Slime.java#L15-L20
🤖 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 `@day02-instance-class/src/main/java/com/survivalcoding/Wizard.java` around
lines 51 - 60, Add null validation for the hero parameter at the beginning of
each method to prevent NullPointerException. In
day02-instance-class/src/main/java/com/survivalcoding/Wizard.java lines 51-60,
add a null check for the hero parameter at the start of the heal method before
any logic executes. Apply the same null validation pattern to
day02-instance-class/src/main/java/com/survivalcoding/GreatWizard.java lines
9-17 in the heal method override and lines 19-27 in the superHeal method.
Additionally, add null validation in
day02-instance-class/src/main/java/com/survivalcoding/Slime.java lines 15-20 at
the start of the attack method to protect the base method that is called by
subclasses. Each null check should return early or print an appropriate error
message if the hero parameter is null.

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