Abstract Class and Abstract Method in Python
Ғылым және технология
Method which is decorated with @abstractmethod and does not have any definition.
Python Don't support Abstract class, So we have ABC(abstract Base Classes) Module, so we can use here to achieve abstract classes. And will see what is abstract class and why we need it. An abstract class can be considered as a pattern for other classes. A class which contains one or more abstract methods is called an abstract class. An abstract method is a method that has a declaration but does not have an implementation.
Support by
becoming a Member : / @telusko
Instamojo (India) : www.instamojo.com/@NavinReddy/
Paypal : www.paypal.me/navinreddy20
UPI : navinreddy20@okicici
BlockChain Full Course : courses.telusko.com/learn/Hyp...
Spring Full Course : courses.telusko.com/learn/Spr...
Spring Full Course (UDEMY) : www.udemy.com/course/spring-5...
Python Full Course (UDEMY) : shorturl.at/EPXZ9
Angular Full Course : courses.telusko.com/learn/Ang...
Rest API in Spring Boot : goo.gl/5Wgsk6
Restful Web Services Tutorial : goo.gl/3mosnz
Spring Boot Tutorials : goo.gl/7894NE
Editing Monitors :
amzn.to/2RfKWgL
amzn.to/2Q665JW
amzn.to/2OUP21a.
Editing Laptop :
ASUS ROG Strix - (new version) amzn.to/2RhumwO
Asus vivoBook :amzn.to/2wS0Hpt
Camera : amzn.to/2OR56AV
lens : amzn.to/2JihtQo
Mics
amzn.to/2RlIe9F
amzn.to/2yDkx5F
amzn.to/2WYqLde
Check out our website: courses.telusko.com
Follow Telusko on Twitter: / navinreddy20
Follow on Facebook:
Telusko : / teluskolearnings
Navin Reddy : / navintelusko
Follow Navin Reddy on Instagram: / navinreddy20
Follow Telusko Official Page : / telusko_edutech
Subscribe to our other channel:
Navin Reddy : / @navinreddy
Telusko Hindi :
/ @teluskohindi
Subscribe to the channel and learn Programming in easy way.
BlockChain Tutorial : bit.ly/2IyH8EJ
Hyperledger Fabric : shorturl.at/ekmCJ
Golang Tutorial : shorturl.at/ksvMP
Servlet JSP tutorial playlist : goo.gl/y1kvwc
Java Tutorial : goo.gl/p10QfB
Kotlin Tutorial : goo.gl/JedEzX
Scala Tutorials for Java Developers : goo.gl/8H1aE5
C Tutorial Playlist : goo.gl/8v92pu
Android Tutorial : goo.gl/MzlIUJ
XML Tutorial : goo.gl/Eo79do
Design Patterns in Java : goo.gl/Kd2MWE
Socket Programming in Java : goo.gl/jlMEbg
Spring MVC Tutorial : goo.gl/9ubbG2
OpenShift Tutorial for Beginners : goo.gl/s58BQH
Spring Framework with Maven : goo.gl/MaEluO
Sql Tutorial for Beginners : goo.gl/x3PrTg
String Handling in Java : goo.gl/zUdPwa
Array in Java : goo.gl/uXTaUy
Java Servlet : goo.gl/R5nHp8
Exception Handling in Java : goo.gl/N4NbAW
Пікірлер: 290
Summary: abstract method is a method which only has declaration and doesn't have definition. a class is called abstract class only if it has at least one abstract method. when you inherit a abstract class as a parent to the child class, the child class should define all the abstract method present in parent class. if it is not done then child class also becomes abstract class automatically. at last, python by default doesn't support abstract class and abstract method, so there is a package called ABC(abstract base classes) by which we can make a class or method abstract.
@Xaveth
3 жыл бұрын
Dude... thank you! Very clear.
@user-bh7rg7eu1k
3 жыл бұрын
Love you, Dude
@likhithap6109
3 жыл бұрын
thank you
@rahulgaonkar3431
3 жыл бұрын
thanx bro
@will44559
3 жыл бұрын
10 minutes video is awesome, 1 minute read paragraph is bravo!
for those who did not understand! assume a situation or an example (u r given a task to design some apps and an app to qualify it must and should contain some specific features like( brightness, notification ).so basically you can declare an abstract class with these feature declarations( brightness, notification ), but not the body in the abstract class and later u inherit them keeping in mind that while you are designing you must and should declare these feature's body for sure along with some more features and u might use the same abstract class for other app design because even it must also contain the specific features along with other, but the body declarations might change from class to class or an app to app if you are doing any real-time work). hope u understood this
Probably need more explanation about this topic. Why we need to create abstract classes. But among all of the youtube videos, this is much much better than others. Thank you...
I see many are still confused with the concept and also with "how is it different from duck typing". Here is an example to get it cleared. This is an exam 'hall' and there are students from 2 diffrent 'classes' seated. Class A has a maths test, Class B has social. The invigilator says that to enter the hall, every one must carry an instrument box. Now students of classes both A and B must bring one even if B class don't have its use. So the class A will have a set of compass, rulers, pencils etc in it. But since students of class B don't have any use, they will just bring one with a pencil or even just empty (pass) because its compulsory to bring one in to be in the hall. If a parent class has an abstract method, every child must also have one. So each child will have to define one of thier own. In duck typing, It isn't necessary to define the parent class method for each child classes. it just simply have to point to the class where the particular method lies. Here we would have to define for each. I hope this helps
@Vishal360
Жыл бұрын
Daymnnn 🤝🏻
wonderful sir, great tutorial, thank you
You just implemented the exact thing that my teacher taugh me in my Object Oriented Design lecture... Thank you so much for the video.....❤
Essentially, you define abstract methods in an abstract class to ensure that it's child classes have a compulsion of having those methods defined inside them
@pranavnyavanandi9710
2 жыл бұрын
Otherwise, the abstract method that is inherited by the child will make it an Abstract Base class thus preventing instantiation. So if we are to instantiate the child class, implementing the abstract methods becomes necessary.
@kunalpandey2066
2 жыл бұрын
we can find its usecase in design patterns
@pranavnyavanandi9710
2 жыл бұрын
@@kunalpandey2066 Hi. Can you elaborate? Design patterns for designing what?
@l3tt3rsnumbers0nly
Жыл бұрын
this explanation makes me understand its use i guess.
@AvyStarr
3 ай бұрын
It's best to use, when we use polymorphism.
it was soooo confusing
@VishuencApp
4 жыл бұрын
Yes, not explained with good examples and details.
@_.sunnyraj._
4 жыл бұрын
No
@sujithkumar_ga
3 жыл бұрын
for those who did not understand! assume a situation or an example (u r given a task to design some apps and an app to qualify it must and should contain some specific features say brightness, notification .so basically you can declare an abstract class with these feature declarations but not the body and later u inherit them in keeping in mind that while design you must and should declare these feature's body for sure along with some more features and u might use the same abstract class for other app design because even it must also contain the specific features along with other but the body declarations might change from class to class or an app to app if you are doing any real-time work). hope u understood this
@vernanonix
3 жыл бұрын
@@sujithkumar_ga So I'm still trying to wrap my head around this. From what I'm seeing, using this video as the example, we declare process in the Computer class as an abstract method and therefore we get an error and to fix that error, we override it in a subclass, say Laptop, by redefining process. So then why even bother with the abstract method at all? Making the abstract method just seems like a waste of time if it's not going to do anything and I have to add the actual definition somewhere else.
@sujithkumar_ga
3 жыл бұрын
@@vernanonix u will get to know better when u do real time projects 👍
Absolutely Brilliant Video! Thanks
This video is quite confusing sir, can you please make one more so that we can understand this concept better.
@hyperskivo8426
4 жыл бұрын
Actually the video is very concise and clear
@_.sunnyraj._
4 жыл бұрын
@@hyperskivo8426 yes
@alwayslakshmipathi2532
3 жыл бұрын
yeah... I felt irritated
@ArjunKrishna-lx1re
3 жыл бұрын
@@hyperskivo8426 then tell me, why we need abstract class
@anindian4601
3 жыл бұрын
@@ArjunKrishna-lx1re 🤣 Good question bro, I Think Navin has missing some logics and codes better we have to refer other utubers too , dont rely on him.
no teacher teaches me that whiteboard example to explain the concept of abstraction,, your a genius sir..
Loved this video! Good explanation , good job.
Thanks a lot sir...please complete data structures and algorithms with python...and if possible start machine learning/data science..as u were telling earlier u we're about to start ...
@meghanadalal9837
4 жыл бұрын
yess yess yessss exactly
@Spinsters_batch
4 жыл бұрын
Yes sir
@sandeepreddy1197
2 жыл бұрын
@@meghanadalal9837 haa yes
@SP-un3rj
2 жыл бұрын
Yes sir please make it
Thank You So Much Sir.
Many many thanks for posting the missed leathers of python. We are waiting for it👌👌👌👌😋😋
Thank you very much!
thank you very much sir for this video
where is your energy man in this tutorial? Btw, U r awesome...
Actually, the function of the abstract class is the programmer shouldn't be able to use a class and its method but he has to provide those methods and its definition to other inheriting classes. By using such a feature the programmer is forcing himself to provide different definitions in inheriting classes. Here what Navin is trying to say is all electronics like laptops desktops and mobiles are computers so the programmers must define all the parts like display and processor to all electronics like laptops desktops and mobiles because without such part they won't work
@samgaines2886
2 жыл бұрын
Thanks for this. Understood the concept but didn’t really get the “why.” This helps
excellent sir
Your grate sir thank so much
Thanks sir for working for us
Can you please explain more on why do we need abstract classes? It's not very clear to me. This will be really helpful. Thanks!
@JoaoVitorBRgomes
2 жыл бұрын
It's a Object Oriented Programming thing. Maybe you are designing many classes and these classes share a common method (in teacher's example is processing(), so each time you inherit in a new class e.g. Laptop, it is mandatory/compulsory that you define processing() method there. I think it is a way to keep organized your OOP project.
@mevlutkaymaz3097
2 жыл бұрын
When you have can possible have multiple(different) output/input, then you will need to create a base class(or abstract class) to use for multiple objects.
@Rafian1924
2 жыл бұрын
Simply, to follow a specific strict structure for the development of functionality.
Good Explanation !
super cool!😺
nice explanation in udemy
nice
Nice
Thank you
Respected and honourable sir ,i have been learning python from scratch only on your KZread channel. I wanna thank you from bottom of my heart.Till now i didn't face any problem or confusion.but now i was Little bit confused about the abstract class, why do we use and why do we need them. ***I have come up with a conclusion that : we use abstract classes and abstract method to override the abstract method again and again in other subclasses of abstract class.*** If it is correct? kindly reply.Big fan sir❤️...God bless you
Please make videos on Python Projects
Sir , make a video on metaclass, why it is used and implementation details..
Thanks for making easy, understanding videos on python. But this one was a bit confusing for non IT people like me!!! Anyways thanks :-)
Sir your specticulars are nice today
Sorry i cant understand very well what u said about when is useful to use an abstract classs only with abstract methods? can you answer me that please
Sir, could you do future videos on how to pass python certificiations, specifically the PCPP (Python institute professional certfied). By the way, brilliant instruction. Thanks
Thank you sir....please do a video on dataclasses in python3.5 and onwards...
Please make lectures on Data Analytics and ML
By the defination, abstraction is used to hide complexity of program but this defination doesn't seems appropriate in python implementation of abstraction.
perfect
Excellent!!! Thank you sir❤️
"If you can't explain a topic, you never understood it well" ~~ Someone
@jayasuryaviswanath2149
3 жыл бұрын
Einstein
sir...please makes video on data structures and algorithms with python please please
plzz make a series on REST API details on python with a hands-on project
Yes it will work, if in inherits
Can you make a video on infrastructure automation using powershell and python
I heard goosebumps in whole video Was it only me
The concept is actually tough to understand here if we don't have basic understanding of Java abstract class.. But very nicely explained. ❤🎉
@temporarychannel4339
Жыл бұрын
This vid isn't clear at all. I only understood b/c I know abstract classes from C++, only then did I understand overriding abstract methods in child classes. Otherwise, the explanation is very unclear but he did show how to create and override abstract classes/methods at least using the custom library.
1. Abstract base class desire its subclass or child class to instantiate the class object by inheriting its base class. 2. ABC methods require to its proceeding methods in a subclass to add the functionality. 3. ABC just def the methods but all its functionality will be designed by a subclass. 4. ABC customize the behaviour of isinstance() and issubclass()
@pranavnyavanandi9710
2 жыл бұрын
Did you know ABC is what is called a "metaclass"?
Please add video for encapsulation concept(__x) to restrict input. Thanks!
Sir please make another video about abstraction class and method..it's too confusing.
Please make a video on multiple inheritance in python.... ☺️
what is difference between interface and abstract class,getting confused on this abstract class and method concept
Thanks for making such helpful video for learners. But I either was not able to understand the ABC concept of class & method by watching this video or video missed the good example of this. Thanks to chatGPT it gave me below real world example which explains the concept really well. e.g. a vehicle might have common attributes like speed, fuel, and methods like start(), stop(), and accelerate(). However, different types of vehicles (e.g., car, motorcycle, truck) might have different implementations for these methods. 1. Vehicle is an abstract base class defining a common interface for all vehicles, with abstract methods like start(), stop(), and accelerate(). 2. Car, Motorcycle, and Truck are concrete subclasses of Vehicle, each providing its own implementation for the abstract methods. 3. Each subclass can have its own specific attributes and methods, but they all must implement the methods defined in the Vehicle base class. below is the code..... from abc import ABC, abstractmethod class Vehicle(ABC): def __init__(self, speed=0, fuel=100): self.speed = speed self.fuel = fuel @abstractmethod def start(self): pass @abstractmethod def stop(self): pass @abstractmethod def accelerate(self): pass class Car(Vehicle): def start(self): print("Car started") def stop(self): print("Car stopped") def accelerate(self): print("Car accelerating") class Motorcycle(Vehicle): def start(self): print("Motorcycle started") def stop(self): print("Motorcycle stopped") def accelerate(self): print("Motorcycle accelerating") class Truck(Vehicle): def start(self): print("Truck started") def stop(self): print("Truck stopped") def accelerate(self): print("Truck accelerating") car = Car() car.start() car.accelerate() car.stop() motorcycle = Motorcycle() motorcycle.start() motorcycle.accelerate() motorcycle.stop() truck = Truck() truck.start() truck.accelerate() truck.stop()
#pytutor Really Helpful..
nothing understood during the last part of video please make a video on this again
sir please bring up a series of python for intermediate
Need more clarity on Abstract Class and Methods
This video made me realize the significance of duck typing.
@_JIT
3 жыл бұрын
Yea ikr. I didnt get what is abs is tbh with this video. it feels like extension of Duck typing video
I am pretty much sure I have missed something, but I am not sure what it is.At 5:11 - I got the concept that if you inherit an Abstract class, the child class will also be Abstract. That I understood, tried and was successful. But didn't properly get the concept after that. If the parent class is an Abstract Class, and if the child class has its own methods, the methods of the child class run without a problem. Have I got it right?
tq
Could you try different examples like Pizza, Burger instead of the Computer, please?
It had taken me 1 hr to properly understand this one....but finally i felt the example was cool. Thank you Sir.
4:50 I expect it to work, because we are creating an object of a concrete rather than abstract class
can you please help with practice problems to go through th concept abstract class
can you explain the concept with real life examples?
Sir this video is little confusing . I used computer inside whiteboard class then I should get the output right ? But I'm getting error that can't instantiate abstract calss whiteboard with abstract mathods process
Is it necessary to implement all the abstract methods in a single sub class??
How to create Final method in Python as I import typing module but it didn't work
Hi @Telisko , Which video editing tool you use ?
@anishnepal3486
4 жыл бұрын
camtasia studio
10:38 Whiteboard class extend Laptop class because it has the implication "definition" of the abstract method "process" otherwise we must implement "define" it inside the Laptop class. am I correct?
Why does this code show an error from abc import ABC, abstractmethod class Computer(ABC): @abstractmethod def process(self): pass class Laptop(Computer): def process(self): print("Running") class Whiteboard(Computer): def write(self): print("Writing") class Program: def work(self, com): print("Working") com.process() c1 = Laptop() c2 = Whiteboard() p1 = Program() p1.work(c1) p1.work(c2) You didn't show the output after you changed whiteboard as a child class.
Sir Assalam o alikum, i am watching your videos on blockchain and i am really very impressed how you explain everything in detail i have a question In hyperledger fabric there are 2 ways to reach consensus endosers and orders. What i am asking is who are endosers if they are admins Doesnt it make hyperledger centralized? Can i be an endoser?
@seferideveloper6933
Жыл бұрын
Ve aleykumselam
We can not create the object of laptop class because inside the laptop class is abstract method if we create the object of abstract so we will get the error
can a non abstract class have abstract methods in python ..in java,c++ its not but what about python
Did he just call me an alien?
I am coding a sign language translation project. i am getting error "Process finished with exit code 134 (interrupted by signal 6: SIGABRT)". can you please help with this reply asap
I have a doubt that, what is the significance of abstract method because method overloading and inheritance seems to be same as abstract classes... couldn't find the difference in between them...can you please help in this?
At 9:51 my output comes only 'solving bugs'..that com.process is not executing..i dont understand what is happening and there is no error showing
Upload a videos on boto3 please
Can we expect a video, explaining Django 3.0 new features..? and advance stuff like cookies and sessions in Django.?
@amanagrawal003
4 жыл бұрын
yes i have exact same question
Sir, please make video on data structure and algorithm in python
@sreekanththota2200
4 жыл бұрын
yes sir...
Is this done to achieve abstraction from oops concept , please I need answer
What can we do about interface like java ? Say, we need to implement strategic design patter like java we cannot use interface ,what should we do then ?
Bro need a video abt encapsulation
The same program i have executed but still the same error TypeError: Can't instantiate abstract class ChildABST with abstract methods AbsMet here in the video naveen executed successfully but it's not when i tried with the same, what's wrong it has i dont understand
how can we define a variable in abstract
can do this namely take instance from child class by abstrac class
What are the benefits of Abstract class? Why do we use it ??
Hi Navin Reddy. I saw all your videos on python for beginners. And all the vids are very useful. I have a situation where i have different data in two files.only one column is common in bith the files. By using the above two files i have to create a new file. How can i do it in python
Previous background was waaaayyyyyy better
yes
why com.process() is used in class Programmer??
When he types println! upppss! :p
Sir it's confusing 😐😐 please make another video for abstract classes and methods 🙏🙏 @Telusko
The println macro at 7:35, you had been writing Rust haha
"interfaces" module will more good representation than abc module....
@DGDG0000000
4 жыл бұрын
Not the same.
Yah....it's was really confusing sir ....how can i get it ?
Very informative video. I have one doubt. I don't agree with this statement - "An abstract method is a method that has a declaration but does not have a definition." We can define the abstract method and use it later with super function. Right?
@haricharan2836
Жыл бұрын
You can
it will work