Hacker News new | ask | show | jobs
by crooked-v 2962 days ago
This is interesting. Though, for my part, rather than...

    class Player {
      playTurn(warrior) {
        warrior.walk();

        ...
      }
    }
...I would much rather have something like...

    import { Warrior } from '@warriorjs/cli';

    class MyWarrior extends Warrior {
      playTurn() {
        this.walk();

        ...
      }
    }
...or...

  function playTurn(warrior) {
    warrior.walk();

    ...
  }
The current style is a weird mix of functional and object-oriented handling.
1 comments

In this particular example, I don't see why. Player and Warrior are conceptually different entities: one is the player of the game, having properties and methods related to controlling gameplay (e.g. a player might play as alternate warriors at different times), the latter is the avatar, having properties and methods related to that fictional characters attributes within the world of the game.

The differences in purpose of the two entities aren't really anything to do with fp vs oop; I don't see what's fp-ish about the first example, and your last example is potentially a weird mix of fp and oop (depending on what "warrior" is, and I can't figure out what use it would be in that context if it wasn't an object with encapsulated methods)