class Hero {
      constructor(name, hp, att) { 
        this.name = name;
        this.hp = hp; 
        this.att = att;
        this.maxHp = hp;
      }
      attack(monster) { 
        monster.hp -= this.att; 
      }
      heal() {
        this.hp = this.maxHp;
      }
    }

    Hero 클래스와 Monster 클래스를 비교해 보세요. 공통부분이 많습니다. 이름, 체력, 공격력 등의 속성과 attack() 메서드가 중복으로 들어 있습니다. 이런 중복 코드는 없앨 수 있지 않을까요?

    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.