• tiramichu@sh.itjust.works
    link
    fedilink
    arrow-up
    65
    ·
    4 hours 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
      link
      fedilink
      arrow-up
      42
      ·
      edit-2
      4 hours 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
        link
        fedilink
        English
        arrow-up
        35
        ·
        edit-2
        4 hours 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();
          }
        }
        
    • FunkyCheese@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      5
      ·
      2 hours ago

      I learned about it in school and we didna few assignments for it

      But… never seen or heard anyone mention it outside of that

      I guess we can make up some nische vases

      I did hear it can be useful for video games though. But then again im sure people can manage fint without, as well

    • vapeloki@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      3 hours ago

      And polymorphism is the only way you could expose those composite Interfaces as bindings on C API based languages. And polymorphism is part of OOP.

      If we take the text book definition of OOP, then the kernel is OOP …