Created
January 11, 2023 00:45
-
-
Save rotelstift/004800aa209e8176a57ec9dd193e4a7c 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 { | |
private final PhysicalAttack physicalAttack; | |
FighterPhysicalAttack(final int baseDamage) { | |
physicalAttack = new PhysicalAttack(baseDamage); | |
} | |
int singleAttackDamage() { | |
return physicalAttack.singleAttackDamage() + 20; | |
} | |
int doubleAttackDamage() { | |
return physicalAttack.doubleAttackDamage() + 10; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment