Hello guys.
So we are going to continue the discussion with respect to Python.
And in this video we are going to discuss about a new topic which is called as abstraction, which is
one of the most important core pillar in oops concept.
Now what exactly is abstraction?
Abstraction is the concept of hiding the complex implementation detail and showing only the necessary
feature of an object.
This helps in reducing programming complexity and effort.
Let me talk about some good examples so that you will be able to understand what does exactly abstraction
mean.
Okay.
Uh, let's consider one thing very simple thing, okay.
With respect to abstraction, if I just want to give you a real world example, I hope everybody uses
a washing machine.
Right.
And if you are using a washing machine in a washing machine, you will be having all the options to
start the washing machine.
How much for what timer?
You have to probably run the washing machine.
You have an option to set the timer.
Along with that, you will be seeing that you'll be having a dryer part.
You know where you'll be able to dry the clothes itself, right?
And just with the help of a click of a button, you will be able to do that specific operation.
Now that buttons that is visible on that washing machine is the thing, or is the feature of that particular
object that is visible to you remaining all the complex implementation?
How how the washing probably takes place, how that particular as soon as you probably click start,
what is the internal process that is going to happen that all complex implementation is completely hidden,
right.
And this is what can be taken as a real world example with respect to abstraction.
Not only that, you can also consider an example with respect to mobile phones, AC remote, your laptop,
your desktop.
You know you'll be able to see buttons are there.
Okay.
You'll be able to see, hey, if I go ahead and probably, uh, touch go if I go ahead and click on
shut down automatically how the system is getting shut down.
If I open a specific application, how that particular application processes process is basically allocated
in the processor, in the Ram, how much memory is basically getting allocated.
So everything is happening in the back end over there, and there are some kind of complex implementation
that is happening in the back end, and that is completely hidden right now in order to make your understand
about abstraction.
Uh, so let me just go and talk with respect to code.
So here I will go ahead and say, hey, from ABC, I'm going to import, uh, ABC.
So this ABC is nothing, but it is for the abstraction.
Uh, it is just for abstract class, you know, which we specifically use.
And let's say if I want to define an abstract method, okay, I will go ahead and define an abstract
method.
I'll talk about what why this method is very much important and all okay.
So first of all let us go ahead and define my abstract class.
Now what is this abstract class?
Let's say that I go ahead and define my vehicle class over here okay.
Now when I'm defining my vehicle class here, I will be considering it as ABC and always remember the
difference between a normal class and an abstract class is that here I will be inheriting this A, B,
c class, right?
And which is nothing, but it is for the abstract class itself.
Right?
Or you can also say abstract base class.
Okay, this is nothing but abstract base class.
Here you can actually see we are inheriting them.
Okay.
Now let's say inside this particular class I have some definition.
And the definition can be anything over here.
Right.
Let's say that I will go ahead and write, uh, um, uh, with respect to vehicle, I will say, hey,
I have a function which is called as drive, okay.
And I will go ahead and print and write some information like, uh, the car, the vehicle, the vehicle
is used for driving.
Okay.
Something like this.
I'm just writing some kind of examples over here.
Now, this is a normal method.
Now let me go ahead and define an abstract method.
Usually when we go ahead and define an abstract method this will be a complete empty function okay.
And the best thing about abstract is that it is created in such a purpose that whenever a child class
inherits this vehicle base class, it says that hey, I am giving you a functionality with respect to
drive, okay?
And I am giving you one abstract method which you can do the implementation with your own way.
Okay, that is what it is basically driven.
So this abstract method is just like giving you the necessary feature of an object.
And it is just hiding the complex implementation detail.
Right.
So here we are just trying to provide you a way.
So let me just go ahead and again repeat this okay.
No.
Let's consider that I'm going to probably write an abstract method over here.
Now in order to define an abstract method we'll go ahead and write definition start engine.
Let's say this is my start engine.
And I will go ahead and write self over here.
And let's say that this is my empty class okay.
Now in abstraction what happens is that as I said, this is my abstract base class.
And this is how we create an abstract method which will be completely empty.
Now, if I probably go ahead and create my child class and let's say this child class is inheriting
the vehicle class.
Now, before inheriting always let's say that if I am inheriting this abstract base class, which is
nothing but vehicle, which is also called as an abstract class, here it says that you can inherit
a you, uh, this This car class.
Class can basically inherit the vehicle class.
But there will be one condition.
You will be able to use this particular method.
But to use this method we have to write our own definition.
Write that the car will basically be writing its own specific definition over here.
Okay.
So in order to show you over here what I will do, I will just go ahead and write definition start underscore
engine okay.
Start underscore engine.
And here we will just go ahead and write the self keyword.
And let's say here we go ahead and write car engine started okay.
So car engine started.
So here you can actually see that I am actually able to write the code right now.
What I am actually going to do.
See now I will just go ahead and initialize something.
You know I'll, I'll, I'll, I'll, uh I'll, I'll, I'll, I'll create a function.
Let me go ahead and create a function saying that operate vehicle.
Okay.
So this will be my function.
And this will basically, uh, demonstrate our entire process of abstraction.
So I will go ahead and just operate vehicle.
And here I'm going to probably write vehicle okay.
Vehicle dot start underscore engine start underscore engine.
Uh.
So vehicle vehicle vehicle spelling needs to be correct.
Start underscore engine.
So here is my start underscore engine.
Now let me define this.
This function is created and it is outside the class okay.
Now let me just go ahead and write car is equal to car.
And now let me just go ahead and call this operate vehicle with respect to car.
So here you will be able to see that what is basically happened here.
This start engine is getting displayed.
Now you need to understand where does abstraction come into mind.
Right here we are just saying that hey there is one functionality okay?
There is one functionality which is available for you.
Right?
And this is basically defined in the form of an abstract method.
And this abstract method, if it is present, if we really need to create an abstract class, we have
to inherit this ABC, right ABC library that we have imported over here.
Now, if any child class wants to inherit this particular abstract base class, we have to make sure
that we will be able to use this particular function.
But along with that, we have to make sure that you have to go ahead and implement this particular function
with your own way.
And that is what we have actually done over here, right?
If I go ahead and also write over here something like this vehicle, let's say if I go ahead and write
vehicle vehicle dot uh along with this dot drive.
So drive will also be able to access it.
Right.
We'll be able to access it.
Now if I go ahead and execute it you can see the vehicle is used for driving.
So the derived class is also able to use this.
But with respect to this abstract method, which is where the abstraction is basically getting applied,
where we are just showing the features of this particular objects.
Right?
We are just showing this particular method, but the complex implementation can be overridden by all
the, uh, derived class that is specifically using them, and that what is basically done over here.
Right.
So this actually gives an example or it makes you understand about the abstraction, uh method over
here with respect to the Python and how you can actually create your abstract class, how you can basically
create an abstract method and how abstract abstraction is basically implemented over here.
But in short, if I really want to discuss abstraction is the concept of hiding the complex implementation
detail and showing only the necessary features of an object.
Right?
So yes, this was it from my side.
I hope you liked this particular video.
I will see you all in the next video.
Thank you.