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()
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.
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.
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")
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
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?
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 ?
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
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!
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.
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?
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.
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
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()
Thank you
Sir basically what's the use of it , for what. Purpose we're going to use it
thanks
p
p
Your intentions are clear - Simply educate and not show off smartness by complicating the content, which other channels do. Keep up your work.
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.
straight to the point, clear, and fun to watch. will binge all ur videos
Thank you, your explanations are clear and is easy enough to understand.
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.
Thanks. Finally I understand now the importance usage of abstract
I got best content thanks for your best class bro☺️☺️
Really simple and straight to the point. Makes it easier to understand more complicated applications later on. Good job!
very understandable
best explanation of abstraction in python on youtube
Thank you for this lessons
This is soo Good of a video and explanation. Thank you, sir!
Great explanation an example, very easy to understand!
Nice brief description of the essentials -- thanks!
excellent explanation
keep it up
Omg, can I just say you are saving my life rn? Thank you for this clear and concise lesson - thank you SO much.
Thank you I was able to understand this concept thanks to your video.
Thank you very much. Wow!! Very simple, very easy, very clear explanation
helped a lot on the basic understanding of the abstract class, which is exactly what I needed for my study, thank you! :)
Awesome tutorial, thanks
Best example
Best explanation.
Loving these short conceptual videos 😁😁❤❤
Wow!
Lovely
Thank you for this video! Amazing explanation
Thank you sir!
Really helpful! Thanks!!
Very nice and useful video
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
awesome video
Amazing
Nice job! Easy to follow examples!
You teach nice
Great tutorial! Thanks a lot, bro! ;)
Excellent explanation, thanks!
Thanks alot ❤️
Very clear and concise explanation. Thank you very much for this!
Really nice, concise, and clear
A very clear explanation. Thanks!
Great discussion Bro
Great explanation bro! Thanks!
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()
Simple & to the point!
finally someone that is able to explain this clear and short! THX a lot!
Thanks a lot! Great explanation! Subscribed and going to take your python and javascript crash courses!
Bless you for making this more clear than my professor.
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.
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
cool video bro... ps: Turn of the cc... it is hilarious!
Ya. Haha🤣.
Now, it's clear for me. Thanks a lot, bro!
It's easy to understand the concept.
Great!
I'm really liking your python tutorials
great video!!
NIce!
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.
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
Thank you!!!
great video !
Great video. To the point. That's how the content should be created. Thanks!
Thank you
It's amazing!Thank you
Thank you Bro!
love u
More content on abstraction and encapsulation while using dataclasses please
Thanks alot.🙏
Sir basically what's the use of it , for what. Purpose we're going to use it
Nicely explained! Thanks :)
Hi bro nice video
nice
Thanks
supporting the channel
Thanks so much I have a test for my Python OOP course tomorrow on this you saved me.
Can someone explain the reason an abstract class would be needed if the child class' methods would be explicitly written anyway?
Спасибо, видео помогло разобраться!
thanks bro
You are just amazing bro
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?
thaaaanks
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 ?
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
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!
Thanks Bro!
tq
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.
I am doing python at university and this is the best video Ive ever watch
for the algorithms. ty brother
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?
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.
@@Craulback Thanks for the explanation
Clear as water!!!
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
Thanks!
quick and dirty.
nice, thanks!
you are a genius bro. thanks 🙂
Why not skip the abstract class completely? You're writing all the code again anyway? What am I missing?
Best tutorial I have ever seen
What if the Vehicle class has attributes?
Do the other classes also have to use them or only methods ?
thank you!
ty bro
Instant like for mentioning the need for speed:)