Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> E.g. Defining a weapon > {sword, wand} hierarchy, with respective properties for melee and casting, and then defining a unique weapon spellsword which is capable of both melee and casting. You could inherit from weapon, and copy & paste sword/wand code, or inherit from sword/wand, and copy & paste the other, but the hierarchy is broken.

Or, you could, in OO Python:

  class SpellSword(Sword, Wand):
    ...
or, possibly even:

  class Melee:

  class Casting:

  class Sword(Melee):

  class Wand(Casting):

  class SpellSword(Melee, Casting):
> So instead of representing the relationships as a tree of inheritance, you represent it as a graph of components (properties).

Multiple inheritance also represents relationships as a graph of properties.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: