OttoVonNoob@lemmy.ca to Programmer Humor@programming.dev · 2 months agoMy friend suggested I use different names for variables..lemmy.caimagemessage-square27fedilinkarrow-up1211arrow-down110file-text
arrow-up1201arrow-down1imageMy friend suggested I use different names for variables..lemmy.caOttoVonNoob@lemmy.ca to Programmer Humor@programming.dev · 2 months agomessage-square27fedilinkfile-text
minus-squarema1w4re@lemm.eelinkfedilinkarrow-up3·edit-22 months agoInheritance 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.
Inheritance established “is a” relationship between classes.
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:
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.