Object oriented programming is a code in paradigm which relies on classes and objects, and classes
are simply viable types, weight attributes and properties.
Those attributes of a class are variables and the properties are methods in the section which are look
at classes and objects, operator overloading method times, inheritance, encapsulation and polymorphic.
Suppose we want to design a program which produces smileys based on some inputs we could define as smiley
framework like this one.
And the way we define such a framework is by defining the class so we can have a class smiley with attributes
like a smile.
So let's do this.
We have an attribute like is smile.
Which is said to true.
We have an attribute like face colour, face colour which is set to white, an attribute like eye colour
which is set to white.
There's actually a string.
So we set up to whites.
Whites.
And then this class could have several properties or methods like, for example, the set smile method.
So since the method we have the deaf set smile.
We turn for now none.
We could define the set face color we turn on.
We have the set eye color.
We turn it on and there we go.
We have our smiling class.
So there we go.
We have this smiley class, which we've defined.
But actually, this class is just a framework.
And to put it alive, we need to make use of an object, which is an instance of this framework or some
sort of version of this framework.
It's coming back to the slide.
As you can see, we have this from here.
We could create an object or an instance of this frame with these color orange, eye color blue, and
then is smile.
That is the smile is true.
Since I could see her smiling, we could also create an object instance where in the face is light blue.
The eye color is red.
And then we also have this other object instance.
Well, if smile is false, I call a white and then face color black.
So from this example, we see how based on this frame, we are able to generate different smileys and
the different versions or instances of this frame or class is what we call the object.
So now let's see how we create a simple object.
We could say smiley, let's say happy with that.
We have this smiley and then we do a happy.
That is smile.
For one, that we have an area, obviously, because this is smile isn't a function but just an attribute.
So take this off or on that we see.
We have happy smile.
Now let's create another object.
We have the objects that smiley you see sad.
That is smile.
Wrong again.
We'll see.
Is still true.
Now one to make Buddhists modify this object size that we have, this is smile to be false.
Now to do this, we could now make use of the set smile functions.
So let's go ahead and modify this.
We're taking the smile or let's say current smile or this is smile status, smile status.
And then we return.
Still known, but what a difference that what we're doing is was set in is smile to be false.
All right is smile is this smile steady is not actually false.
So this smile the smile stage is a one of change.
This attribute of the class to become now while we put in here so set smile now gets in your all set
smile takes in the smile attitude and then modifies it is smile.
And then from this now which I'll see while we get after passenger to set smile function so around this
obviously is true but once the defined is which is that set smile and then we see false wrong again
and we see that we have an error.
Now this error reads that the set smile takes one positional argument but somewhere given.
Okay, before looking at this, let's do some recap.
We have defined this object that is, we have defined version of the smiley class, which is sad.
Previously we had defined as other version happy of those smiley class.
And then yeah, we're like Colleen on this set smile function, which is other set smile method, which
is part of the smiley class.
So what we do is we have set that set smile and then we pass in the smile status, which is false obviously
if was sad and the smile status to be false so is smiley should be false.
Now, once it has this, we are now ready to call again on its smile to be sure that is actually false.
But then we have in this error.
Now having this error is very normal and we shall see how to solve this problem or how to correct this.
The way we correct this error is by giving each object some sort of identity in this class.
So what we're going to do now is instead of just defining the methods in the class as if all the objects
behaved the same, we are going to give it an identity.
So we have would define the self right here and then.
Now we have self, self and for this year we have self, self, self.
This is actually a key word using Python and other programming languages like Java.
You have this now coming back to this where we define our attributes and then we've added one extra
argument in all our functions.
Now the reason why we're doing this is because we want to give this class or right to give each object
created based on this class an identity which is going to be different from this other one right here.
So this means that whenever we create this or if we create an object they happy from this class is going
to have a different identity from this other one.
By identity will mean is going to have a different way of working with this functions or methods.
And also the attributes are going to be different.
And this is done simply by using this self.
Now, that said, let's run this.
We see that we have an error.
We thought that a solve is not defined.
Now, the way we solve this is by including a constructor.
So instead of having to put this attribute all the way we've just done, we are going to define a constructor.
And the constructor is just a special type of matter.
So we have this in its method.
This init method is what we call the constructor.
Not that you cannot see.
For example, you cannot do this.
You can just define in there like this and then expect it to work.
So this indeed has to have to double on the cars before and then two on this class after.
So double before and then double after.
Once we have this, now it's in this constructor that would define those attributes for the class or
actually this object attributes.
So now let's run again.
You see that everything works fine now.
And that's simply because this attribute, all right.
Of this class has been defined such that we could now, for every object, define its own attributes.
There's an error here.
We shall skip this.
Like we should just run this for now.
So let's run again.
We see that we have this error and take note.
We must also have the self that's passing in.
Neat.
So let's run again.
And there we go.
It works fine now.
So obviously this is Smile belonged to the class smiley but now this is smile is actually the is smile
for this happy object.
And the way we did this was by using the South and then by including a constructor.
So on that.
That's fine.
Now, let's come back to this or this.
And there we go.
We see that this time around, the code works fine.
But we are having a true instead of a false.
So what do we do to solve this problem?
The simple way we could solve this problem is by instead of saying is smile as if this is smile belonged
to the class.
We have self that is smile.
So that Python knows that this is smile is actually the attribute for this set object.
So let's run again.
And there we go.
Everything works fine.
Now we have this as false.
So sad.
That is smile is false and happy.
That is smile.
It's true.
We could go ahead and modify this again.
Let's suppose we want to do this in a way that undefined in the smile we just see.
For example, we see the past and the status quo is smile status, is smile status.
And then instead of having this status of run this, we have an arrow.
Because normally the way the construct has been defined, we have all we are meant to pass in any value
right here.
So what we do is we're going to have this yeah, we'll see this smile.
So by default, we will set it to true.
By default is true.
So now.
Yeah, we have the smile.
Okay, let's run this again.
And there we go.
We set out without having to explicitly call on the set smile method.
We already have the set turn to false.
All the is smile for set then to false.
Let's take this off.
So you see that it works.
So that's it.
So we see that setter is smiles false because of the way it was defined.
And that was the role of this init function, which is actually a constructor.
So we are constructing this object based on this class.
By already defining a smile in such a way that it is true.
And the case where we have, for example, just happy by default years since we don't pass anything
by default, it's true.
And then when we want it to be false, we have just to specify that I want it to be false.
Now the next step will be to take this and say, okay, this color will repeat for the first color we
set it to default whites.
We do the same for the I color.
We set it to default.
Whites That's it.
So that we then we go, we have the face color.
Yeah, we have the face color around this.
Everything was fine.
Let's now set this face color to see orange.
Orange.
And then we have said, now let's put it in black.
We have a black.
The slight that's a black said the face color.
So on that that we go so we see that now our side is good.
Most of this of print simply print is.
Wrong again.
Okay.
So now we have four black.
And then we could also obviously into the eye color.
Eye color?
No, I closed white.
So just take this will let.
So let's print out now the eye color.
Sad that I actually saw that eye color on it.
There we go.
We have the face.
Got a black, eye color black.
And then this is smiles false.
So this isn't as the smile and smiley.