331
OOP at home: (feddit.nu)
you are viewing a single comment's thread
view the rest of the comments
[-] tiramichu@sh.itjust.works 176 points 3 weeks ago

I'll say this now.

Inheritance is the most misused capability of OOP which programmers think makes their code look smart, but most of the time just makes a giant fucking mess.

[-] red_tomato@lemmy.world 105 points 3 weeks ago* (last edited 3 weeks ago)

Hold on, I’m in the middle of drawing an inheritance graph so I know how Dog is related to AircraftCarrier.

[-] blackn1ght@feddit.uk 79 points 3 weeks ago* (last edited 3 weeks ago)
public interface ICanTravelThroughTheAir
{

}

public class Flea : ICanTravelThroughTheAir
{

}

public class AircraftCarrier
{
  private readonly List<ICanTravelThroughTheAir> _aircraft = new();

  public void AddAircraft(ICanTravelThroughTheAir flyingThing)
  {
    _aircraft.Add(flyingThing);
  }
}

public class Dog : AircraftCarrier
{
    public void Woof()
    {
        Console.WriteLine("Bitch I'm an aircraft carrier!");
    }
}

public static class Program
{
  public int Main(string[] args)
  {
    var dog = new Dog();
    
    for (var i = 0; i < 10000; i++)
    {
        dog.AddAircraft(new Flea());
    }

    dog.Woof();
  }
}
[-] ZILtoid1991@lemmy.world 3 points 3 weeks ago* (last edited 3 weeks ago)

Now someone needs to make it an entity component system!

Attempt 1:

public struct Entity {
  bool isDog : 1;
  bool isAircraftCarrier : 1;
  bool isFlea : 1;
  bool canFlyInAir : 1;
  ubyte opt_numOfAircrafts : 4;
  int entityID;
  int opt_parentID;
  static Entity createDog(int entityID) {
    Entity result;
    result.isDog = true;
    result.entityID = entityID;
    return result;
  }
  static Entity createFlea(int entityID) {
    Entity result;
    result.isFlea = true;
    result.canFlyInAir = true;
    result.entityID = entityID;
    return result;
  }
  void addAirCraft(ref Entity aircraft) {
    if (aircraft.canFlyInAir && this.isAircraftCarrier) {
      aircraft.opt_parentID = this.entityID;
      this.opt_numOfAircrafts++;
    }
  }
  void woof() {
    if (isDog) {
      if (isAircraftCarrier) writeln("I'm a motherfucking aircraft carrier");
      else writeln("Woof!");
    }
  }
}

void main() {
  Entity dog = Entity.createDog(1);
  Entity flea = Entity.createFlea(2);
  dog.woof();
  dog.isAircraftCarrier = true;
  dog.addAirCraft(flea);
  dog.woof();
}
[-] a_jackal@pawb.social 4 points 3 weeks ago

You forgot the component part.

[-] WhyJiffie@sh.itjust.works 1 points 2 weeks ago* (last edited 2 weeks ago)

but but why would you do that?

load more comments (6 replies)
load more comments (6 replies)
load more comments (35 replies)
this post was submitted on 10 Feb 2026
331 points (95.8% liked)

Programmer Humor

30189 readers
1275 users here now

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

founded 2 years ago
MODERATORS