Hi, everybody, and welcome.
I'm super excited to continue teaching object oriented programming, as in my personal opinion, this
is the most interesting and most useful topic in the whole course.
OK, so it doesn't matter if you're planning to become a front end developer or a back end developer
or an automation developer, if you're going to use Python in your work, you must dominate the old
topic.
If you recall from the previous video, we have set up a number of goals, a number of topics to study,
and we have studied part of them.
Let's have a quick overview.
All right.
First of all, we have seen the hierarchy inside by charm.
We have seen what a module, class method and variable right afterwards.
We have learned how to create a simple class, in our case, core class, which has a simple variable
and a single print action.
Then with the help of this class, we have also tried to create an instance of an object.
We have two of them, Aldy, a three and four focus.
These topics bring us halfway, but we need to add some more knowledge in order to create professional
objects that could be very useful in our programming in the future and in the present as well.
So usually I know that I'm starting off explaining the terminal terminology, but today I think will
begin off from a simple example.
This example will conclude all of these three parts as well.
Let's go over them quickly.
First of all, we'll learn what our properties are an object and we will cover the function.
We will also study how to use the self parameter of a property and we're going to cover objects methods.
So let's dive deep into this example and go from the top.
Just follow my lead and everything's going to be just fine.
It's not too complicated once you break down these topics into small bricks.
So we have created a class here class, his name is employee, and this class contains three methods.
OK, the first method is death, OK?
And we know that all of these are methods because the def keyword indicates that this is a method.
All right.
And we can see here like a new type of method that we haven't seen before.
The method has underscore then in it and then additional underscore, OK, we haven't encountered this
method or these type of methods before.
And that's because it's a reserved method.
It's a special method that PI charm who invented by charm, made it this this way that this method can't
be used in any different way but inside the objects.
OK, we will ignore this method for the next minute and we will get back to it afterwards.
So we have here two simple methods attendance, attendance, check and show employees details and we
have a certain point action inside them.
But I want to focus on this bottom part right here.
OK, we have two instances here.
OK, you can see it's an instance because we have a name that we picked Sarah and Michael, and then
we have the equals equals sign and then we mention the name of the class.
OK, so this is exactly what we did in the previous video, right?
We have set a name then both equals and then we have the name of the class.
But in this case, we haven't passed any variables inside the class while here we're passing variables
inside these brackets that will be passed into the class.
Correct.
OK, so we have here two instances of an object and let's go over them and see the flow of the code
and what's going on over here.
And obviously, these five last lines are outside of the class as everything's inside.
The class is with indention, with spaces, while everything here is without indention.
So this is outside of the class.
And these are objects instances that we're going to explain right now.
Jumping for one last time up in here, we can also hear see here that the three and four focus also
does not have indention once we compare it to the class indention level.
So these two are outside of the class as well.
All right, so if we take this Michael Instant's right here, we can see his type is he's an employee,
OK?
Michael is an employee, his type is employee.
OK, it doesn't go we're not going to go into details what that means right now.
But what we need to know now is that we have created an instance, which is name is Michael and Michael
is an employee.
OK, just imagine to yourself that we have a program here, often of an office manager of some office,
OK?
And she has this program that she must feel employees details their each new employee comes to her and
she needs to fill these details for each and every one of them.
OK, so this is what she will do.
OK.
She would ask each employee what's what is his name, what the salary that he's making, even that they're
basically illegal.
All right.
But let's go with it.
And then she would ask him whether he was being at work for the last week.
OK, just like invent something, just trying to improvise here, OK?
So she must she must ask each of the each of the employees these three questions and she needs to get
data from them.
OK, so Michael, obviously this is the name of the instance, OK, but here are the questions that
he's going to be asked.
What's your name.
Michael.
How much do you make?
Three thousand.
And did you, uh, did you attend to work all the last week?
True or false?
OK, so you can see the number one here.
So this Michael variable starts off here.
OK, so here's the instance of an object.
And after we write it down here, it's going to go.
The following flow from here is going to get up to the top.
And inside this init method, this init method is called the constructor.
A constructor basically builds up an employee in our case inside the program.
OK, so it receives these three variables name, salary and attendance from each of these instances
separately.
OK, so we're going to discuss Michael first.
So it receives these three variables from Michael name, salary and attendance and obviously from the
top here from the method declaration goes the name goes inside here because it's the same thing which
is using it here.
Here's the declaration.
And here we use it goes in here, salary and attendance.
OK, and from this right part is going it's going to the self name.
Self name is the property of these instances.
OK, self name is a property of Michael.
So we are having Michael variable here.
It's basically the same thing as we're doing.
For example, X equals five plus X equals five plus one.
OK, so whatever is at the right goes inside to what's in the left.
OK, so the name is Michael and it goes straight into this bar, the left bar here, self name, self
name is called a property of an object and it is stored somewhere in the memory of the computer.
As long as your code is running.
What that means is that as long as we have said as we have clicked right.
Click on the file and clicked run as long as this will run.
Once we passed this line right here, Michael equals employee.
These variables would be stored somewhere in the memory, somewhere, the memory for our future usage.
OK, and we also have Sarah, OK, this is the instance of Sarah, the office manager, ask her the
same questions.
So the first user name, salary and a tendency and these three variables where it went again up in here
inside of def name, salary and attendance.
And then from here they went to here, here and here.
And then they went inside the self parameter, the self parameter, which is the property.
And also Sarah's details are stored in the memory as well.
OK, and now once we passed this part, once we passed the instance by the.
Creation of an instant sport.
OK, now we can do stuff with these with these properties, OK, we can apply manipulation on them,
we can print them, we can do anything.
OK, so from these parameters, from these properties here, they can be used inside every method which
is inside this class.
OK, so from here, from the cell number three, we can use these variables inside the methods.
OK, so if we're talking about Michael and we want to show employee details, for example, we want
to use this method, OK?
We want to use this method and this method.
What it does is it brings the string name and then OK.
And then it prints self dot name, OK.
In Michael's case, the name, which is the first variable here and the first here, and the name is
Michael as a string.
So what we'll get here is name to Dot Michael and then salary two dots and then self salary.
Self salary.
You can see here the second variable and also here is the second it will get the number three thousand,
OK?
It goes from here to here to here.
And then to hear, OK, this is the flow, I specifically roll down the numbers so it will be easy to
keep track of the data flow.
OK, and this is basically it.
And then once we want to show employee details of Sarah, OK, we're going to do the same thing, like
we're going to put Sarah Dot and then then the name of the method.
We're calling out the method with Sarah's properties.
This is what we're doing.
We're not writing employee dot show employee details because we won't have any properties.
We created Sarah.
We have set variables into her and now we can using this method with her properties.
OK.
So this is basically it.
I think we have covered all of this, all of these parts pretty much deeply as much as we can.
And now let's go to explaining these terms in much more clear way.
Is a text OK, visual explanation in helpful of a tax explanation.
So we have created an employee class.
OK, that class represents a standard employee in a certain company.
Each employee must have the following properties.
He must have them.
Each employee that we creating, for example, we have Sarah, which is employee Michael employee.
Each of these employees must contain name, salary and attendance status.
We have created to object instances.
OK, Sarah.
Like this.
OK, Sarah and Michael, and we have set these variables inside each of them, OK, then variables are
passed to each instance, employee's name, salary and attendance.
These variables would be collected by the in its special method and stored for each instance.
OK, so the Init method collects them and stores them.
Then the deaf init method receives the variables from the object instances and then converts them into
property of an object.
This happens right here.
We have the variable and it is converted that converted equalized to the property of the instance.
Then the properties, these properties which are saved, are used whenever any method is called by an
object instance.
OK, so once you want to call a certain method, for example, show employee details, it's called out
by the name of the instance instance name DOT Method.
All right, and that's about it.
OK, I saw you go back to the cold example and review the flow of the variable using the marker marked.
No, but we already did it.
OK, the variable is inserted into the instance.
Then it goes up in here to the in it and then from the unit, it goes inside the unit and then it can
be used in every method inside the class.
I really thought that it would be very useful to show a live good example of what we just seen.
OK, so we have Sarah incents Michael Instant's sorry, Sarah and Michael and we have these methods
printed out.
OK, so let's just run it.
There you go, so what's what are these all these prints?
First of all, we have you know what?
Let me just remove this so we won't get confused.
All right.
So right now, we have just have this, Sarah, incidents that we have created and out of it we want
to print out, we want to execute actually the show employee details method, OK, this is this method.
So we have inserted this variable O as first, this one a second, this method.
And from here, OK, they are passed up to the in it and from here the name goes up in here and then
this property is used in each of these methods.
You can see when I marked it and it's marked right here as well.
So just pass the inside.
And the name is unique for each of these instances here.
The name is Sarah here.
The name is Michael.
So I wanted to print out Sarah's.
Details, OK?
The name of the instance that the method.
OK, so once we do that, we simply get.
Name.
OK, then we have Silvani, which is Sarah's name.
All right.
And then we have the celery and selfs celery, but what is this self celery, the self celery is self
that got from here, that goes from here, here and here.
OK, so this is what will be printed out and same goes for Michael.
OK, so if we do the same thing for Michael.
We'll get his details as well and just we have here another are another matter.
Let's try to print it.
I'm going to do Michael Dott attendance check.
OK, same thing.
Michael's properties go inside this method and we have here his name and then like s attendance status
is.
And then we converted the attendance again.
Why did we do it?
It's casting because it's a boolean, right?
The attendance.
This one.
And this one is a boolean.
OK, and here we're printing out strings, so we need to do the casting.
So we wanting to print out the attendance check of Michael, let's do it and see what happens.
There you go, Michael, sit down.
This is true.
OK, and you can see that this variable passed through all these baths and went up on here, OK, and
then we do this the following thing for as well, OK?
You can see Sarah's attendance is false, and that's because this is this false boolean variable appears
up here.
All right.
So I'm very happy that we have covered all of these topics.
Basically, now we can do whatever we want using all of these parts.
So we have the instance of an object.
We have the init method.
We have the self parameter, and we have classes, methods.
We know how to use all of them.
And in the next lectures, we'll have some challenging assignments and we'll try to use them in a more
complex way.
After seeing a live called example and the next lecture, I think you'll be ready to do some training.
And also a special project is waiting for you like a mega assignment.
But don't worry, I'm just trying to make you stronger and make you dominators in object oriented programming.
Thank you.
And we'll see you in the next lecture.