Created
October 25, 2021 13:58
-
-
Save theScottyJam/4d502807fca1ab7ce9ebf69d7599a05f to your computer and use it in GitHub Desktop.
Article: Composition Alone Can't Replace Inheritance - public helpers
This file contains 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
// Public helpers | |
export const monsterBehaviors = { | |
kill(monster) { | |
userInventory.add(monster.dropLoot()) | |
removeFromUi(this) | |
} | |
} | |
// private helpers | |
const monsterHelpers = { | |
attack() { | |
playHurtAnimation() | |
} | |
} | |
export class Slime { ... } | |
export class Skeleton { ... } | |
export class Clown { | |
dropLoot() { | |
return [new Key()] | |
} | |
attack() { | |
monsterHelpers.attack() | |
if (itsTime()) { | |
showCutScene() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment