var Turtle1 var Turtle2 var Is_Turtle

    •  Dr. Wesker   ( @wesker@lemmy.sdf.org ) 
      link
      fedilink
      English
      4
      edit-2
      8 days ago

      When you start learning about different paradigms, you’ll likely learn much more about inheritance when learning about the Object Oriented design paradigm.

      To overly simplify, you create objects that inherit attributes from other objects. It’s for instance a way to create reusable patterns, that have stronger and more reliable data structures.

      I made the joke comment, because for instance, you could create a Turtle class, and always know it was a Turtle. Again, an oversimplification.

      EDIT: I should also add that for some reason OOP is an oddly divisive subject. Developers always seem to want to argue about it.

    •  ma1w4re   ( @ma1w4re@lemm.ee ) 
      link
      fedilink
      3
      edit-2
      8 days ago

      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.