Object oriented programming is the fact that the code is highly reusable.
Suppose now that instead of this kind of round that Somalis are apart from this kind of round, the
Somalis want to be able to create.
This kind of square like Smiley's.
It's clear already that an attribute like the radius, which is one of the attributes of this Smiley's,
is no longer an attribute for this square like Smiley.
And also the way we saw calculate the total area of the smiley of the square like Smiley is moving from
the where we shall calculate the total area of this circle shaped Smiley's and clearly most of the attributes
as you could see here this is smiley face color eye color.
I maintained that for those squares small smiley's and then there's only this radius which is not maintained
because it's not needed.
When working with Square, Smiley is also for the methods.
As we could see, it's maybe only the head area.
Yeah.
Where there's going to be a modification for this.
There's no modification.
So basically there's going to be a modification for this and this.
Now what do we do?
Do we recreate like say let's insert this, let's go up.
It is again this year.
Do we have to come and see, um, square smiley?
So we create a square smiley.
We take this off and then, yeah, maybe we just see we have a no.
So that's his site.
And so radius now we have the side on the side.
Desmond, in that five, you know we have self that side, equal side and then for the area we have
side times side.
So take this off.
There we go.
Now it's possible to rewrite this class this way, but making use of the object oriented programming
paradigm, we could implement inheritance.
Now, inheritance in this case can be clearly seen as the square.
Smiley has many properties that are included in the model class as a smiley self because there's some
sort of subclass to this model class.
SMILEY So what we could do is now make this square.
Smiley inherits the useful properties from the Smiley, and then we'll just do some slight modifications
on the square smiley in about to use it.
So let's come back to this.
Suppose we have the square smiley let's, let's run this for now.
So, yeah, we replace this a square.
SMILEY Yeah.
Now let's run it now.
Clearly this is not correct because it doesn't have a radius run again.
That's it.
Let's print those things off.
Let's print this.
That's been a smile.
And that's fine.
Let's also let's also get the area.
So let's say had happy the had area and then as in no running the pass in the side because that's been
passed already in the constructor.
So run that we have this let's go back to this.
We have solved side square.
So this didn't solve.
Okay, you'll run again.
There's a method.
So we have that run.
There we go.
So now we just have to square it.
Nine, for example, you have 81.
That's normal.
Now let's take out most part of this code since actually, as I could see clearly most part of this
is similar to what we are already reading right here, and that's the power of object oriented programming
and inheritance.
So as you can see, we could make this square smiley as subclass of this smiley class.
By doing that suffices to just write your smiley and that's all.
So we have subclass Square Smiley and then we have this main class Smiley, the subclass Square Smiley
which inherits from Smiley.
While this is done, we could take this off.
So take this off.
Be careful.
Now think of the hat area because we need that for run this everything so we could check out this function
which was defined previously as is equals face friend is I equal face or on that?
We told that this is not defined.
We need to put this, uh, happy.
Okay.
So in this case, we have since we put it in the default parameters, the face colour is the same as
the eye colour.
So that's correct.
Now let's see.
After defined in happy uh while defined in happy with defined the face colour to be equals the red or
on that is now is false.
Now suppose we want to make use of the attributes from those smiley.
Given that we are inheriting from Smiley.
What we could do is we could take of this portion.
Now, this side is actually specific to this square smile class, so we can take that off.
Since the main, the superclass has this and I reduce by default.
But then this three attributes are also the same for those smiley.
So that's why we could make use of this.
And then to actually make use of those attributes, we use a super key word.
Now we have that.
Now we have in it.
And there we go.
Now the way we use the super is such that we could actually replace this by the smiley itself.
So we just like saying, why is it calling on the constructor of the smiley and it will call on the
contract of the smiley means.
We are taking into consideration actually all of those attributes.
So that set we have this smiley in it and then in this we could pass in these different attributes.
So yeah, we have this smiley face colour and eye colour.
That's fine.
We have the self on that and you see that everything works.
Okay.
Yeah, we have the happy that is smile, that's the is smile attribute and it gives us a true whereas
we didn't explicitly define the smile attribute here.
Now if we take this of let's put this back to super.
We have this error.
Now, if you have to use a super instead of the regular square smiley, then we will have to put in
the square Somalia.
All right.
I've got to use a super instead of the smiley as we used it, because what we just did was we had this
smiley and that was fine.
We had the is smile without problem.
Now, if we have to use that super key word, then we define it like this and then pass in the square.
Smiley will solve.
We have this output, which is normal because the way we're defined is we pass in the south.
Yeah.
Which wasn't necessary because we are not passing any object in this unit right here.
So that said, we remove that and then we present this now.
So let's run that.
And there we go.
We still have the same result we had, as well as if we're having a smiley here.
Note that if we take this off, see, not even works.
It's been doing it wrong again.
It's important to note that apart from this kind of direct inheritance where we have, for example,
the square smiley inherit in from the smiley, we could also have multi-level inheritance.
So we could have a two with the square smiley.
So suppose we have a3d Square smiley which inherits from the Square Smiley and the Square Smiley Intern
inherits from Smiley.
So we could have this three d square smiley.
Right?
Yeah.
Let's do that.
And this inherits, as we've said, from the square smiley.
Apart from this, we could also have c o hexagonal smiley.
One, two, three.
Let's say we have one, two, three, four, five, six.
So we're defined as Hexagon Smiley, which inherits directly from Smiley.
So he does not know we go.
So we could have this kind of inheritance.
We see that we have Smiley.
This inherits from Smiley, this from Smiley.
And then this inherits from Square Smiley.
And obviously, all this and force is called reusability and also code meant and ability.