• 0 Posts
  • 30 Comments
Joined 10 months ago
cake
Cake day: January 12th, 2024

help-circle
















  • Inheritance established “is a” relationship between classes.

    class Turtle;  
    class TigerTurtle is a Turtle (but better);  
    class BossTurtle is a Turtle (but better);  
    

    Underlying classes hold an inner object to the super class, everything from Turtle will be in TigerTurtle and BossTurtle.

    In some languages that is configurable with public, private, protected keywords.

    Relatedly, there’s also composition, which establishes a “has a” relationship:

    class TurtleTail;
    class Turtle:
      var tail: TurtleTail; (has a tail);
    

    Since Turtle is NOT a tail, but a whole animal, turtle should not inherit TurtleTail. But it HAS a tail, thus we add turtle tail as a property.