Why Can’t We Instantiate Abstract Classes

Поделиться
HTML-код
  • Опубликовано: 23 янв 2025

Комментарии • 15

  • @compositeboson123
    @compositeboson123 17 дней назад +9

    dang thats actually one of the best explanations ı have ever heard ngl

  • @alexgraham108
    @alexgraham108 17 дней назад +4

    For viewers:
    It is possible to Remove the “ABC” base class from the Animal class. This will allow you to instantiate.
    By inheriting from the ABC base, you are essentially telling the class that you do not want it to be instantiated as it’s own class & that you’re going to create subclasses from the “blueprint” as said in the video.
    Another key point I’d like to add is that it is possible to have the @abstractmethod decorator on any class method (whether or not you inherit from ABC)
    This has a similar advantage of subclasses being required to implement those methods. Without instance issues!

    • @rida_brahim
      @rida_brahim 17 дней назад

      this is bad, this way it creates too much confusion, an abstract class should enforce it's methods like other oop languages and not let any class use this decorator

  • @byaruhaf
    @byaruhaf 16 дней назад +1

    So they are like interfaces in java or protocols in swift?

  • @MaxSamoha
    @MaxSamoha 17 дней назад +2

    Great

    • @2MinutesPy
      @2MinutesPy  17 дней назад

      Thanks for your support

  • @Mindingsesssion
    @Mindingsesssion 14 дней назад

    If we have a second abstract class, for example Mammals, is it possible for Mammals to inherit from ABC and Animals in python ?

    • @SaiponathGames
      @SaiponathGames 14 дней назад

      Yes, Python supports Multiple Inheritance

  • @dweepverma3662
    @dweepverma3662 17 дней назад +2

    If abstract classes is for design enforcement then why would anyone create an object of it...

    • @notpowder5831
      @notpowder5831 17 дней назад

      instantiated an object when?

    • @notpowder5831
      @notpowder5831 17 дней назад

      he should create an abstract class named Creature that is implemented by Animal

    • @Jbombjohnson
      @Jbombjohnson 16 дней назад

      You wouldn’t - that’s the entire point.
      His last example changes the abstract class into a concrete class where it’s no longer just an abstract blueprint, but a proper, fully implemented class.

  • @nottomention-h8w
    @nottomention-h8w 17 дней назад +2

    Ohhh okay... Got it