Python abstract classes 👻

Поділитися
Вставка
  • Опубліковано 29 лис 2024

КОМЕНТАРІ • 160

  • @BroCodez
    @BroCodez  3 роки тому +46

    TLDR
    # Prevents a user from creating an object of that class
    # + compels a user to override abstract methods in a child class
    # abstract class = a class which contains one or more abstract methods.
    # abstract method = a method that has a declaration but does not have an implementation.
    from abc import ABC, abstractmethod
    class Vehicle(ABC):
    @abstractmethod
    def go(self):
    pass
    @abstractmethod
    def stop(self):
    pass
    class Car(Vehicle):
    def go(self):
    print("You drive the car")
    def stop(self):
    print("This car is stopped")
    class Motorcycle(Vehicle):
    def go(self):
    print("You ride the motorcycle")
    def stop(self):
    print("This motorcycle is stopped")
    #vehicle = Vehicle()
    car = Car()
    motorcycle = Motorcycle()
    #vehicle.go()
    car.go()
    motorcycle.go()
    #vehicle.stop()
    car.stop()
    motorcycle.stop()

  • @shrikanthsingh8243
    @shrikanthsingh8243 2 роки тому +66

    Your intentions are clear - Simply educate and not show off smartness by complicating the content, which other channels do. Keep up your work.

  • @forrestelliott3267
    @forrestelliott3267 2 роки тому +49

    This was really helpful, thank you. Though I think at 4:57 the error arose from the vehicle = Vehicle() line, not from the motorcycle = Motorcycle() line, as your commentary implies at that moment.

  • @guardmanbob
    @guardmanbob 3 роки тому +8

    straight to the point, clear, and fun to watch. will binge all ur videos

  • @yuilhan4275
    @yuilhan4275 3 роки тому +9

    Thank you, your explanations are clear and is easy enough to understand.

  • @yevhenliubarskyi1841
    @yevhenliubarskyi1841 2 роки тому +8

    Thank you Bro, your explanations are just crystal clear. I've already watched several of your videos. Hope you achieve great success with your channel.

  • @zacky7862
    @zacky7862 3 роки тому +2

    Thanks. Finally I understand now the importance usage of abstract

  • @ravikanthduvvuri392
    @ravikanthduvvuri392 3 роки тому +4

    I got best content thanks for your best class bro☺️☺️

  • @trippingwithcrujo7708
    @trippingwithcrujo7708 Рік тому +1

    Really simple and straight to the point. Makes it easier to understand more complicated applications later on. Good job!

  • @CKARlife
    @CKARlife 3 роки тому +3

    very understandable

  • @Ronnie9P
    @Ronnie9P 3 роки тому +1

    best explanation of abstraction in python on youtube

  • @joelpaquete4152
    @joelpaquete4152 2 роки тому

    Thank you for this lessons

  • @svensalvatore8702
    @svensalvatore8702 Рік тому

    This is soo Good of a video and explanation. Thank you, sir!

  • @simeonbogg3725
    @simeonbogg3725 2 роки тому

    Great explanation an example, very easy to understand!

  • @jackb4223
    @jackb4223 3 роки тому +1

    Nice brief description of the essentials -- thanks!

  • @cesarosantini708
    @cesarosantini708 3 роки тому +2

    excellent explanation
    keep it up

  • @MissMisc-n3d
    @MissMisc-n3d 8 місяців тому

    Omg, can I just say you are saving my life rn? Thank you for this clear and concise lesson - thank you SO much.

  • @davidrowlands8548
    @davidrowlands8548 2 роки тому

    Thank you I was able to understand this concept thanks to your video.

  • @erickonyanda5570
    @erickonyanda5570 3 роки тому +1

    Thank you very much. Wow!! Very simple, very easy, very clear explanation

  • @גייסוןחן
    @גייסוןחן 5 місяців тому

    helped a lot on the basic understanding of the abstract class, which is exactly what I needed for my study, thank you! :)

  • @softwareengineer8923
    @softwareengineer8923 6 місяців тому

    Awesome tutorial, thanks

  • @abdulhameedmalik4299
    @abdulhameedmalik4299 Місяць тому

    Best example

  • @SuccessXcel_
    @SuccessXcel_ Рік тому

    Best explanation.

  • @hooman3669
    @hooman3669 5 місяців тому

    Loving these short conceptual videos 😁😁❤❤

  • @beingzero7541
    @beingzero7541 2 роки тому +1

    Wow!

  • @kemann3815
    @kemann3815 2 роки тому

    Lovely

  • @liasantos6639
    @liasantos6639 11 місяців тому

    Thank you for this video! Amazing explanation

  • @83sal
    @83sal 3 роки тому +2

    Thank you sir!

  • @RajatSadanandan
    @RajatSadanandan 3 роки тому +2

    Really helpful! Thanks!!

  • @georgitanev-w4b
    @georgitanev-w4b 2 роки тому

    Very nice and useful video

  • @davidstefanov9210
    @davidstefanov9210 3 роки тому +1

    Thank you for the video dude,It was very helpful and informative. BTW my Teacher linked this video in our Python course as a example

  • @hiiexisthiiexist1284
    @hiiexisthiiexist1284 Рік тому

    awesome video

  • @ImranAli-wh4rw
    @ImranAli-wh4rw 19 днів тому

    Amazing

  • @stevechesney9334
    @stevechesney9334 Рік тому

    Nice job! Easy to follow examples!

  • @priyanshagarwal1565
    @priyanshagarwal1565 8 місяців тому

    You teach nice

  • @otsapin
    @otsapin 3 роки тому +2

    Great tutorial! Thanks a lot, bro! ;)

  • @MrPimleemans
    @MrPimleemans Рік тому

    Excellent explanation, thanks!

  • @reshmi003
    @reshmi003 2 роки тому +1

    Thanks alot ❤️

  • @linatroshka
    @linatroshka 2 роки тому

    Very clear and concise explanation. Thank you very much for this!

  • @akramal-fageeh8969
    @akramal-fageeh8969 5 місяців тому

    Really nice, concise, and clear

  • @pablocesarlopez7379
    @pablocesarlopez7379 Рік тому

    A very clear explanation. Thanks!

  • @myoutube8832
    @myoutube8832 8 місяців тому

    Great discussion Bro

  • @d1jn
    @d1jn 2 роки тому +1

    Great explanation bro! Thanks!

  • @MystikPrae
    @MystikPrae Рік тому

    from abc import ABC,abstractmethod
    class Animal(ABC):
    @abstractmethod
    def eat(self):
    print("This is eating something")
    class Rabbit(Animal):
    def eat(self):
    print("This is eating grass")

    obj=Rabbit()
    obj.eat()

  • @hrushikeshsahasrabuddhe5103

    Simple & to the point!

  • @Muertedertod
    @Muertedertod 2 роки тому

    finally someone that is able to explain this clear and short! THX a lot!

  • @roxykvarman8773
    @roxykvarman8773 3 роки тому +2

    Thanks a lot! Great explanation! Subscribed and going to take your python and javascript crash courses!

  • @timhiggins7072
    @timhiggins7072 Рік тому

    Bless you for making this more clear than my professor.

  • @nirutg5130
    @nirutg5130 Рік тому

    I find 6-7 sources from internet to understand about Python abstraction but not understand!, just understand from this video. Thank you so much Bro.

  • @horoshuhin
    @horoshuhin 2 роки тому

    this is such a concise and to-the-point explanation of ABC. I've yet to find a better one. and probably don't need to anyway. thank you

  • @anfedres
    @anfedres 3 роки тому +2

    cool video bro... ps: Turn of the cc... it is hilarious!

  • @andrewv8350
    @andrewv8350 4 місяці тому

    Now, it's clear for me. Thanks a lot, bro!

  • @cloudroot7
    @cloudroot7 2 роки тому

    It's easy to understand the concept.

  • @HeribertoCarreras
    @HeribertoCarreras 2 місяці тому

    Great!

  • @Franco-ss4bu
    @Franco-ss4bu 11 місяців тому

    I'm really liking your python tutorials

  • @effdimusic
    @effdimusic Рік тому

    great video!!

  • @igordjokic
    @igordjokic Рік тому

    NIce!

  • @Midas_Mindset
    @Midas_Mindset 3 дні тому

    Great stuff man, I've been learning a lot of these concepts from your videos and you've been doing a great job of explaining.

  • @shingaling3315
    @shingaling3315 Рік тому +1

    I understand the implementation but what is the purpose of doing this? I’m not following what benefit was gained by going through this versus not defining an abstract class at all

  • @soklin
    @soklin 2 роки тому

    Thank you!!!

  • @SuperMaker.M
    @SuperMaker.M 11 місяців тому

    great video !

  • @nishantrandev9633
    @nishantrandev9633 2 роки тому

    Great video. To the point. That's how the content should be created. Thanks!

  • @TheHansdampf80
    @TheHansdampf80 10 місяців тому

    Thank you

  • @theverynvg
    @theverynvg Рік тому

    It's amazing!Thank you

  • @henriquefelinimena7433
    @henriquefelinimena7433 3 роки тому +2

    Thank you Bro!

  • @HussainAli-sb1dv
    @HussainAli-sb1dv Рік тому

    love u

  • @chriskeo392
    @chriskeo392 2 роки тому

    More content on abstraction and encapsulation while using dataclasses please

  • @DaganKaahiye
    @DaganKaahiye Рік тому

    Thanks alot.🙏

  • @lovelyaashik9732
    @lovelyaashik9732 2 роки тому +3

    Sir basically what's the use of it , for what. Purpose we're going to use it

  • @macieks3604
    @macieks3604 Рік тому

    Nicely explained! Thanks :)

  • @streamindigoflags8035
    @streamindigoflags8035 Рік тому

    Hi bro nice video

  • @uuhju7004
    @uuhju7004 3 роки тому

    nice

  • @rubenc4696
    @rubenc4696 7 місяців тому

    Thanks

  • @jhassee
    @jhassee 2 роки тому

    supporting the channel

  • @icchigoat
    @icchigoat Рік тому

    Thanks so much I have a test for my Python OOP course tomorrow on this you saved me.

  • @sterlingevans129
    @sterlingevans129 Рік тому +2

    Can someone explain the reason an abstract class would be needed if the child class' methods would be explicitly written anyway?

  • @ВаняМихнюк-ш9д
    @ВаняМихнюк-ш9д 5 місяців тому

    Спасибо, видео помогло разобраться!

  • @mrnepomuceno
    @mrnepomuceno 2 роки тому

    thanks bro

  • @abdullahnasir8535
    @abdullahnasir8535 Рік тому

    You are just amazing bro

  • @kerry7932
    @kerry7932 Рік тому

    Nice video. I think we need some additional information about the purpose of abstract classes as many of the comments have indicated. That is, is if subclasses cannot inherit from their parent, what is the purpose of the parent?

  • @jimenadelgado7384
    @jimenadelgado7384 7 місяців тому

    thaaaanks

  • @amenkalai8442
    @amenkalai8442 Рік тому +1

    I didn't get this one? what's the point of using abstract classes? why are we preventing a class from creating an object ?? how can this help us and benefits us in real life projects ?

    • @HTWwpzIuqaObMt
      @HTWwpzIuqaObMt 5 місяців тому

      I will present you a practical example: Lets say you are working with sockets and you find that your server class has some common functionality with your client class. You would create an abstract base class which encapsulates the common functionalities of the two classes and defines the required classes for the socket. Ex. A start_socket function and a handle_connection function. These are abstract methods which will be implemented by the children of the class appropriately. Use abstract methods to outline how a child class should work

  • @digosantista
    @digosantista 2 роки тому

    Cool. But it would be nice to comment on the video (or do a voice over) to let people know that error arouse from Vehicle being instatiated not from implementation itself.
    Other than that, great! Thanks!

  • @tarikyassa1076
    @tarikyassa1076 3 роки тому +1

    Thanks Bro!

  • @dave371
    @dave371 2 дні тому

    tq

  • @JosédaSilva-z5y
    @JosédaSilva-z5y 7 місяців тому

    You are very clear and objective. But I can't understand the use of abstract class if you can't instantiate it and the same functions are written bellow in other classes???
    Thanks in advance.

  • @santosbogo
    @santosbogo 2 роки тому

    I am doing python at university and this is the best video Ive ever watch

  • @chillydoog
    @chillydoog Рік тому

    for the algorithms. ty brother

  • @samiam.402
    @samiam.402 3 роки тому +5

    I might've missed it, did he explain why you don't have to "super()" the methods you are overriding? Is this an inherent part of an abstract class, or am I missing something?

    • @Craulback
      @Craulback 3 роки тому +3

      super() gets the child class access to the attributes from the parents method, it doesn't override anything, but is useful when your child class needs the same attributes, plus some new one.
      class Child(Parent)
      def __init__(self,attribute_1,attribute_2,attribute_3)
      super().__init__(attribute_1,attribute_2) # this will pull the first 2 attributes (of the same name) from the parent
      as for overriding, just defining the child's method using the same name as the one in the parent will override it for the child class.
      it looks for the "go()" method in the child class, before looking for the one from the parent.
      so it never actually encounters the abstract version of the method.

    • @sebastianradlmeier8922
      @sebastianradlmeier8922 2 роки тому +1

      ​@@Craulback Thanks for the explanation

  • @xBaphometHx
    @xBaphometHx Рік тому

    Clear as water!!!

  • @SmokyDesperado91
    @SmokyDesperado91 2 роки тому +1

    Thank you, great explanation! I have one question though: is there some way to create abstract attributes in analogy to abstract methods? I want to make sure that those attributes will be implemented in all child classes

  • @EissaAlahdul
    @EissaAlahdul 2 роки тому

    Thanks!

  • @pun15h3r.
    @pun15h3r. 7 місяців тому

    quick and dirty.
    nice, thanks!

  • @Amirkolo
    @Amirkolo 9 місяців тому

    you are a genius bro. thanks 🙂

  • @kreglfromworld
    @kreglfromworld 2 роки тому +1

    Why not skip the abstract class completely? You're writing all the code again anyway? What am I missing?

  • @omercagla8970
    @omercagla8970 Рік тому

    Best tutorial I have ever seen

  • @50lek
    @50lek Місяць тому

    What if the Vehicle class has attributes?
    Do the other classes also have to use them or only methods ?

  • @marianotorres4052
    @marianotorres4052 2 роки тому

    thank you!

  • @lw9954
    @lw9954 2 роки тому

    ty bro

  • @nazarsilchenko8326
    @nazarsilchenko8326 3 роки тому

    Instant like for mentioning the need for speed:)