var Turtle1 var Turtle2 var Is_Turtle

You are viewing a single thread.
View all comments View context
3 points
*

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.

permalink
report
parent
reply
3 points
*

I’m only commenting because the actual python is practically pseudo code:


# A turtle class
class Turtle:
    shell=True

# A boss class
class Boss:
    authority=True

#A class that inherits from another
class TigerTurtle(Turtle):
    fuzzy=True

# Multiple inheritance, or "The Devil's Playground"
class TigerBossTurtle(TigerTurtle, Boss):
    #  shell, authority, and fuzzy are all true
    ...
permalink
report
parent
reply
2 points

It is simpler than my faulty memory remembers, time to learn python again 😁

permalink
report
parent
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 6.9K

    Monthly active users

  • 731

    Posts

  • 11K

    Comments