9. Dragon ADR Damage Take

  • ADR - Architecture Design Records

9.1. Problem

  • Make DMG points damage to the dragon

dragon ---> enemy
dragon -> enemy
dragon <-> enemy
dragon <- enemy
dragon <--- enemy

9.2. Option 1

>>> dragon.take_damage(DMG)
>>> dragon.hurt_self(DMG)
>>> dragon.receive_damage(DMG)
  • Good: dragon ---> enemy

9.3. Option 2

>>> dragon.wound(DMG)
>>> dragon.hurt(DMG)
>>> dragon.hit(DMG)
>>> dragon.damage(DMG)
  • Good: dragon -> enemy

  • Bad: dragon -> enemy

9.4. Option 3

>>> dragon - DMG
>>> dragon -= DMG
  • Good: simple

  • Good: can use .__sub__() for validation if needed

  • Bad: requires knowledge of API

9.5. Option 4

>>> dragon - Damage(20)
>>> dragon -= Damage(20)
  • Good: simple

  • Good: can use .__sub__() for validation if needed

  • Bad: requires knowledge of API

9.6. Option 5

>>> dragon.health - DMG
>>> dragon.health -= DMG
  • Good: simple

  • Good: can use @property for validation if needed

  • Bad: requires knowledge of API

  • Bad: encapsulation

9.7. Option 6

>>> dragon.health - Damage(20)
>>> dragon.health -= Damage(20)
  • Good: simple

  • Good: can use @property for validation if needed

  • Bad: requires knowledge of API

  • Bad: encapsulation

9.8. Option 7

>>> dragon.__sub__(DMG)
>>> dragon.__isub__(DMG)
  • Good: encapsulation

  • Bad: not Pythonic way

  • Bad: not simple

  • Bad: requires knowledge of API

9.9. Option 8

>>> dragon.set_damage(DMG)
  • Good: encapsulation

  • Bad: not Pythonic way

  • Bad: set_damage() indicates setter of damage field

9.10. Decision

>>> dragon.take_damage(DMG)
  • Good: encapsulation

  • Good: easy

  • Good: dragon ---> enemy