Created
January 11, 2023 00:43
-
-
Save rotelstift/ba9b15e91ac5e32bf875932c04730488 to your computer and use it in GitHub Desktop.
良いコード/悪いコードで学ぶ設計入門を読んで書いたコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Main { | |
public static void main(String[] args) { | |
final FighterPhysicalAttack fighterPhysicalAttack = new FighterPhysicalAttack(50); | |
System.out.println(fighterPhysicalAttack.singleAttackDamage()); | |
System.out.println(fighterPhysicalAttack.doubleAttackDamage()); | |
} | |
} | |
class PhysicalAttack { | |
private final int baseDamage; | |
PhysicalAttack(final int baseDamage) { | |
this.baseDamage = baseDamage; | |
} | |
int singleAttackDamage() { | |
return baseDamage; | |
} | |
int doubleAttackDamage() { | |
return singleAttackDamage() + singleAttackDamage(); | |
} | |
} | |
class FighterPhysicalAttack extends PhysicalAttack { | |
FighterPhysicalAttack(final int baseDamage) { | |
super(baseDamage); | |
} | |
@Override | |
int singleAttackDamage() { | |
return super.singleAttackDamage() + 20; | |
} | |
@Override | |
int doubleAttackDamage() { | |
return super.doubleAttackDamage() + 10; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment