• red_tomato@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    4 months 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
      1
      ·
      edit-2
      4 months 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();
        }
      }
      
        • Supercrunchy@programming.dev
          link
          fedilink
          arrow-up
          0
          ·
          4 months ago

          And dependency injection!

          Every class needs to use DI for calling other classes, even though we’ll have anyway just a single implementation for all of them, and we won’t be using this flexibility at all (not even for tests where it might be useful for mocking dependencies).