1
00:00:00,120 --> 00:00:04,020
Object oriented programming is the fact that the code is highly reusable.

2
00:00:05,700 --> 00:00:12,060
Suppose now that instead of this kind of round that Somalis are apart from this kind of round, the

3
00:00:12,060 --> 00:00:14,430
Somalis want to be able to create.

4
00:00:16,160 --> 00:00:18,860
This kind of square like Smiley's.

5
00:00:19,670 --> 00:00:27,830
It's clear already that an attribute like the radius, which is one of the attributes of this Smiley's,

6
00:00:28,670 --> 00:00:32,210
is no longer an attribute for this square like Smiley.

7
00:00:33,140 --> 00:00:41,690
And also the way we saw calculate the total area of the smiley of the square like Smiley is moving from

8
00:00:41,690 --> 00:00:51,560
the where we shall calculate the total area of this circle shaped Smiley's and clearly most of the attributes

9
00:00:51,740 --> 00:00:55,370
as you could see here this is smiley face color eye color.

10
00:00:55,610 --> 00:01:01,460
I maintained that for those squares small smiley's and then there's only this radius which is not maintained

11
00:01:01,670 --> 00:01:03,230
because it's not needed.

12
00:01:03,260 --> 00:01:07,790
When working with Square, Smiley is also for the methods.

13
00:01:08,450 --> 00:01:12,860
As we could see, it's maybe only the head area.

14
00:01:13,010 --> 00:01:13,420
Yeah.

15
00:01:13,790 --> 00:01:16,670
Where there's going to be a modification for this.

16
00:01:16,670 --> 00:01:18,380
There's no modification.

17
00:01:18,380 --> 00:01:19,610
There's no modification.

18
00:01:19,610 --> 00:01:20,840
There's no modification.

19
00:01:21,260 --> 00:01:25,670
So basically there's going to be a modification for this and this.

20
00:01:26,300 --> 00:01:27,530
Now what do we do?

21
00:01:27,530 --> 00:01:33,600
Do we recreate like say let's insert this, let's go up.

22
00:01:33,710 --> 00:01:35,390
It is again this year.

23
00:01:35,930 --> 00:01:41,210
Do we have to come and see, um, square smiley?

24
00:01:41,300 --> 00:01:43,640
So we create a square smiley.

25
00:01:43,640 --> 00:01:48,830
We take this off and then, yeah, maybe we just see we have a no.

26
00:01:49,220 --> 00:01:50,350
So that's his site.

27
00:01:50,420 --> 00:01:53,740
And so radius now we have the side on the side.

28
00:01:53,750 --> 00:02:02,360
Desmond, in that five, you know we have self that side, equal side and then for the area we have

29
00:02:02,930 --> 00:02:05,210
side times side.

30
00:02:05,210 --> 00:02:06,320
So take this off.

31
00:02:07,130 --> 00:02:07,700
There we go.

32
00:02:07,970 --> 00:02:16,760
Now it's possible to rewrite this class this way, but making use of the object oriented programming

33
00:02:16,760 --> 00:02:20,450
paradigm, we could implement inheritance.

34
00:02:21,050 --> 00:02:27,830
Now, inheritance in this case can be clearly seen as the square.

35
00:02:27,830 --> 00:02:37,490
Smiley has many properties that are included in the model class as a smiley self because there's some

36
00:02:37,490 --> 00:02:41,720
sort of subclass to this model class.

37
00:02:41,840 --> 00:02:47,200
SMILEY So what we could do is now make this square.

38
00:02:47,210 --> 00:02:55,490
Smiley inherits the useful properties from the Smiley, and then we'll just do some slight modifications

39
00:02:55,490 --> 00:02:58,130
on the square smiley in about to use it.

40
00:02:59,420 --> 00:03:00,810
So let's come back to this.

41
00:03:00,830 --> 00:03:04,970
Suppose we have the square smiley let's, let's run this for now.

42
00:03:05,540 --> 00:03:07,310
So, yeah, we replace this a square.

43
00:03:07,460 --> 00:03:09,010
SMILEY Yeah.

44
00:03:09,030 --> 00:03:11,030
Now let's run it now.

45
00:03:13,640 --> 00:03:17,600
Clearly this is not correct because it doesn't have a radius run again.

46
00:03:18,350 --> 00:03:18,950
That's it.

47
00:03:19,520 --> 00:03:22,520
Let's print those things off.

48
00:03:22,820 --> 00:03:24,380
Let's print this.

49
00:03:25,580 --> 00:03:26,750
That's been a smile.

50
00:03:27,200 --> 00:03:27,860
And that's fine.

51
00:03:28,730 --> 00:03:30,500
Let's also let's also get the area.

52
00:03:30,500 --> 00:03:42,320
So let's say had happy the had area and then as in no running the pass in the side because that's been

53
00:03:42,320 --> 00:03:44,000
passed already in the constructor.

54
00:03:44,270 --> 00:03:48,770
So run that we have this let's go back to this.

55
00:03:48,770 --> 00:03:51,200
We have solved side square.

56
00:03:51,200 --> 00:03:52,610
So this didn't solve.

57
00:03:54,050 --> 00:03:55,160
Okay, you'll run again.

58
00:03:57,060 --> 00:03:58,040
There's a method.

59
00:03:58,040 --> 00:03:59,630
So we have that run.

60
00:03:59,690 --> 00:04:00,260
There we go.

61
00:04:00,440 --> 00:04:03,000
So now we just have to square it.

62
00:04:03,020 --> 00:04:04,880
Nine, for example, you have 81.

63
00:04:04,880 --> 00:04:05,570
That's normal.

64
00:04:06,020 --> 00:04:13,910
Now let's take out most part of this code since actually, as I could see clearly most part of this

65
00:04:14,180 --> 00:04:21,080
is similar to what we are already reading right here, and that's the power of object oriented programming

66
00:04:21,200 --> 00:04:22,760
and inheritance.

67
00:04:23,570 --> 00:04:29,720
So as you can see, we could make this square smiley as subclass of this smiley class.

68
00:04:30,110 --> 00:04:33,710
By doing that suffices to just write your smiley and that's all.

69
00:04:33,950 --> 00:04:42,710
So we have subclass Square Smiley and then we have this main class Smiley, the subclass Square Smiley

70
00:04:42,710 --> 00:04:44,900
which inherits from Smiley.

71
00:04:45,680 --> 00:04:48,620
While this is done, we could take this off.

72
00:04:49,070 --> 00:04:50,630
So take this off.

73
00:04:51,830 --> 00:04:52,280
Be careful.

74
00:04:52,280 --> 00:05:00,860
Now think of the hat area because we need that for run this everything so we could check out this function

75
00:05:00,860 --> 00:05:13,130
which was defined previously as is equals face friend is I equal face or on that?

76
00:05:15,310 --> 00:05:17,140
We told that this is not defined.

77
00:05:18,280 --> 00:05:20,650
We need to put this, uh, happy.

78
00:05:21,490 --> 00:05:21,940
Okay.

79
00:05:22,210 --> 00:05:28,360
So in this case, we have since we put it in the default parameters, the face colour is the same as

80
00:05:28,360 --> 00:05:29,110
the eye colour.

81
00:05:29,110 --> 00:05:30,040
So that's correct.

82
00:05:30,550 --> 00:05:32,440
Now let's see.

83
00:05:32,440 --> 00:05:39,960
After defined in happy uh while defined in happy with defined the face colour to be equals the red or

84
00:05:40,000 --> 00:05:41,380
on that is now is false.

85
00:05:41,860 --> 00:05:47,480
Now suppose we want to make use of the attributes from those smiley.

86
00:05:47,950 --> 00:05:50,590
Given that we are inheriting from Smiley.

87
00:05:51,220 --> 00:05:54,520
What we could do is we could take of this portion.

88
00:05:55,000 --> 00:06:02,380
Now, this side is actually specific to this square smile class, so we can take that off.

89
00:06:03,160 --> 00:06:08,050
Since the main, the superclass has this and I reduce by default.

90
00:06:08,710 --> 00:06:15,550
But then this three attributes are also the same for those smiley.

91
00:06:16,000 --> 00:06:18,250
So that's why we could make use of this.

92
00:06:18,640 --> 00:06:24,290
And then to actually make use of those attributes, we use a super key word.

93
00:06:25,240 --> 00:06:26,320
Now we have that.

94
00:06:27,220 --> 00:06:28,210
Now we have in it.

95
00:06:29,530 --> 00:06:30,700
And there we go.

96
00:06:31,030 --> 00:06:37,540
Now the way we use the super is such that we could actually replace this by the smiley itself.

97
00:06:37,540 --> 00:06:44,080
So we just like saying, why is it calling on the constructor of the smiley and it will call on the

98
00:06:44,080 --> 00:06:45,420
contract of the smiley means.

99
00:06:45,700 --> 00:06:49,740
We are taking into consideration actually all of those attributes.

100
00:06:50,560 --> 00:06:59,560
So that set we have this smiley in it and then in this we could pass in these different attributes.

101
00:07:00,100 --> 00:07:07,960
So yeah, we have this smiley face colour and eye colour.

102
00:07:09,160 --> 00:07:09,900
That's fine.

103
00:07:09,910 --> 00:07:14,440
We have the self on that and you see that everything works.

104
00:07:14,440 --> 00:07:14,970
Okay.

105
00:07:15,430 --> 00:07:23,800
Yeah, we have the happy that is smile, that's the is smile attribute and it gives us a true whereas

106
00:07:23,800 --> 00:07:27,610
we didn't explicitly define the smile attribute here.

107
00:07:27,910 --> 00:07:30,970
Now if we take this of let's put this back to super.

108
00:07:33,660 --> 00:07:34,710
We have this error.

109
00:07:35,340 --> 00:07:42,090
Now, if you have to use a super instead of the regular square smiley, then we will have to put in

110
00:07:42,090 --> 00:07:44,490
the square Somalia.

111
00:07:44,550 --> 00:07:44,940
All right.

112
00:07:44,940 --> 00:07:49,860
I've got to use a super instead of the smiley as we used it, because what we just did was we had this

113
00:07:50,010 --> 00:07:52,410
smiley and that was fine.

114
00:07:52,830 --> 00:07:55,800
We had the is smile without problem.

115
00:07:56,070 --> 00:08:04,070
Now, if we have to use that super key word, then we define it like this and then pass in the square.

116
00:08:04,530 --> 00:08:06,840
Smiley will solve.

117
00:08:09,880 --> 00:08:14,230
We have this output, which is normal because the way we're defined is we pass in the south.

118
00:08:14,230 --> 00:08:14,650
Yeah.

119
00:08:14,710 --> 00:08:20,500
Which wasn't necessary because we are not passing any object in this unit right here.

120
00:08:21,040 --> 00:08:25,360
So that said, we remove that and then we present this now.

121
00:08:26,380 --> 00:08:27,400
So let's run that.

122
00:08:27,640 --> 00:08:28,280
And there we go.

123
00:08:28,300 --> 00:08:35,050
We still have the same result we had, as well as if we're having a smiley here.

124
00:08:36,850 --> 00:08:42,040
Note that if we take this off, see, not even works.

125
00:08:43,420 --> 00:08:45,520
It's been doing it wrong again.

126
00:08:46,720 --> 00:08:52,660
It's important to note that apart from this kind of direct inheritance where we have, for example,

127
00:08:52,990 --> 00:08:59,920
the square smiley inherit in from the smiley, we could also have multi-level inheritance.

128
00:09:00,220 --> 00:09:04,570
So we could have a two with the square smiley.

129
00:09:04,600 --> 00:09:12,790
So suppose we have a3d Square smiley which inherits from the Square Smiley and the Square Smiley Intern

130
00:09:12,790 --> 00:09:14,050
inherits from Smiley.

131
00:09:14,470 --> 00:09:17,890
So we could have this three d square smiley.

132
00:09:17,890 --> 00:09:18,120
Right?

133
00:09:18,130 --> 00:09:18,520
Yeah.

134
00:09:18,760 --> 00:09:19,960
Let's do that.

135
00:09:20,260 --> 00:09:23,710
And this inherits, as we've said, from the square smiley.

136
00:09:24,460 --> 00:09:30,700
Apart from this, we could also have c o hexagonal smiley.

137
00:09:30,720 --> 00:09:32,670
One, two, three.

138
00:09:32,710 --> 00:09:38,070
Let's say we have one, two, three, four, five, six.

139
00:09:38,080 --> 00:09:43,920
So we're defined as Hexagon Smiley, which inherits directly from Smiley.

140
00:09:43,930 --> 00:09:48,790
So he does not know we go.

141
00:09:49,180 --> 00:09:51,280
So we could have this kind of inheritance.

142
00:09:52,030 --> 00:09:53,800
We see that we have Smiley.

143
00:09:53,800 --> 00:09:55,990
This inherits from Smiley, this from Smiley.

144
00:09:56,200 --> 00:09:59,560
And then this inherits from Square Smiley.

145
00:10:00,340 --> 00:10:08,050
And obviously, all this and force is called reusability and also code meant and ability.
