1
00:00:00,270 --> 00:00:08,970
Object oriented programming is a code in paradigm which relies on classes and objects, and classes

2
00:00:08,970 --> 00:00:15,510
are simply viable types, weight attributes and properties.

3
00:00:17,550 --> 00:00:26,700
Those attributes of a class are variables and the properties are methods in the section which are look

4
00:00:26,700 --> 00:00:35,580
at classes and objects, operator overloading method times, inheritance, encapsulation and polymorphic.

5
00:00:35,970 --> 00:00:46,560
Suppose we want to design a program which produces smileys based on some inputs we could define as smiley

6
00:00:46,950 --> 00:00:48,390
framework like this one.

7
00:00:49,080 --> 00:00:58,440
And the way we define such a framework is by defining the class so we can have a class smiley with attributes

8
00:00:58,440 --> 00:01:01,110
like a smile.

9
00:01:01,140 --> 00:01:02,730
So let's do this.

10
00:01:02,940 --> 00:01:05,310
We have an attribute like is smile.

11
00:01:07,910 --> 00:01:09,230
Which is said to true.

12
00:01:10,250 --> 00:01:20,720
We have an attribute like face colour, face colour which is set to white, an attribute like eye colour

13
00:01:21,530 --> 00:01:22,970
which is set to white.

14
00:01:23,870 --> 00:01:25,070
There's actually a string.

15
00:01:25,070 --> 00:01:26,450
So we set up to whites.

16
00:01:28,710 --> 00:01:29,580
Whites.

17
00:01:33,670 --> 00:01:44,260
And then this class could have several properties or methods like, for example, the set smile method.

18
00:01:44,710 --> 00:01:49,030
So since the method we have the deaf set smile.

19
00:01:51,260 --> 00:01:53,190
We turn for now none.

20
00:01:53,550 --> 00:02:00,870
We could define the set face color we turn on.

21
00:02:02,490 --> 00:02:05,640
We have the set eye color.

22
00:02:08,750 --> 00:02:11,920
We turn it on and there we go.

23
00:02:11,930 --> 00:02:13,610
We have our smiling class.

24
00:02:15,860 --> 00:02:16,700
So there we go.

25
00:02:16,700 --> 00:02:19,130
We have this smiley class, which we've defined.

26
00:02:20,150 --> 00:02:23,930
But actually, this class is just a framework.

27
00:02:24,170 --> 00:02:31,700
And to put it alive, we need to make use of an object, which is an instance of this framework or some

28
00:02:31,700 --> 00:02:33,470
sort of version of this framework.

29
00:02:33,980 --> 00:02:35,180
It's coming back to the slide.

30
00:02:35,330 --> 00:02:37,930
As you can see, we have this from here.

31
00:02:38,480 --> 00:02:46,430
We could create an object or an instance of this frame with these color orange, eye color blue, and

32
00:02:46,430 --> 00:02:48,200
then is smile.

33
00:02:48,200 --> 00:02:50,780
That is the smile is true.

34
00:02:51,020 --> 00:02:59,420
Since I could see her smiling, we could also create an object instance where in the face is light blue.

35
00:03:00,800 --> 00:03:02,240
The eye color is red.

36
00:03:02,900 --> 00:03:05,960
And then we also have this other object instance.

37
00:03:06,170 --> 00:03:11,570
Well, if smile is false, I call a white and then face color black.

38
00:03:12,380 --> 00:03:21,240
So from this example, we see how based on this frame, we are able to generate different smileys and

39
00:03:21,320 --> 00:03:29,630
the different versions or instances of this frame or class is what we call the object.

40
00:03:30,980 --> 00:03:33,260
So now let's see how we create a simple object.

41
00:03:33,260 --> 00:03:38,870
We could say smiley, let's say happy with that.

42
00:03:38,870 --> 00:03:44,270
We have this smiley and then we do a happy.

43
00:03:44,750 --> 00:03:46,670
That is smile.

44
00:03:49,800 --> 00:03:58,560
For one, that we have an area, obviously, because this is smile isn't a function but just an attribute.

45
00:03:58,570 --> 00:04:00,840
So take this off or on that we see.

46
00:04:00,870 --> 00:04:02,140
We have happy smile.

47
00:04:02,430 --> 00:04:05,700
Now let's create another object.

48
00:04:05,820 --> 00:04:11,130
We have the objects that smiley you see sad.

49
00:04:11,370 --> 00:04:13,680
That is smile.

50
00:04:15,390 --> 00:04:16,020
Wrong again.

51
00:04:16,020 --> 00:04:16,380
We'll see.

52
00:04:16,380 --> 00:04:17,130
Is still true.

53
00:04:17,490 --> 00:04:24,270
Now one to make Buddhists modify this object size that we have, this is smile to be false.

54
00:04:24,720 --> 00:04:29,820
Now to do this, we could now make use of the set smile functions.

55
00:04:31,200 --> 00:04:32,850
So let's go ahead and modify this.

56
00:04:32,850 --> 00:04:43,350
We're taking the smile or let's say current smile or this is smile status, smile status.

57
00:04:43,620 --> 00:04:44,790
And then we return.

58
00:04:46,170 --> 00:04:53,550
Still known, but what a difference that what we're doing is was set in is smile to be false.

59
00:04:54,720 --> 00:04:57,840
All right is smile is this smile steady is not actually false.

60
00:04:57,840 --> 00:05:00,360
So this smile the smile stage is a one of change.

61
00:05:00,360 --> 00:05:09,630
This attribute of the class to become now while we put in here so set smile now gets in your all set

62
00:05:09,630 --> 00:05:12,690
smile takes in the smile attitude and then modifies it is smile.

63
00:05:13,170 --> 00:05:20,910
And then from this now which I'll see while we get after passenger to set smile function so around this

64
00:05:21,540 --> 00:05:32,850
obviously is true but once the defined is which is that set smile and then we see false wrong again

65
00:05:34,080 --> 00:05:35,610
and we see that we have an error.

66
00:05:35,910 --> 00:05:43,470
Now this error reads that the set smile takes one positional argument but somewhere given.

67
00:05:43,860 --> 00:05:48,420
Okay, before looking at this, let's do some recap.

68
00:05:48,420 --> 00:05:56,340
We have defined this object that is, we have defined version of the smiley class, which is sad.

69
00:05:57,270 --> 00:06:00,780
Previously we had defined as other version happy of those smiley class.

70
00:06:01,230 --> 00:06:09,960
And then yeah, we're like Colleen on this set smile function, which is other set smile method, which

71
00:06:09,960 --> 00:06:11,880
is part of the smiley class.

72
00:06:12,120 --> 00:06:19,620
So what we do is we have set that set smile and then we pass in the smile status, which is false obviously

73
00:06:19,860 --> 00:06:23,880
if was sad and the smile status to be false so is smiley should be false.

74
00:06:24,360 --> 00:06:30,360
Now, once it has this, we are now ready to call again on its smile to be sure that is actually false.

75
00:06:31,590 --> 00:06:33,180
But then we have in this error.

76
00:06:34,080 --> 00:06:41,260
Now having this error is very normal and we shall see how to solve this problem or how to correct this.

77
00:06:42,390 --> 00:06:48,570
The way we correct this error is by giving each object some sort of identity in this class.

78
00:06:49,110 --> 00:06:58,110
So what we're going to do now is instead of just defining the methods in the class as if all the objects

79
00:06:58,110 --> 00:07:01,140
behaved the same, we are going to give it an identity.

80
00:07:01,140 --> 00:07:05,670
So we have would define the self right here and then.

81
00:07:05,690 --> 00:07:15,540
Now we have self, self and for this year we have self, self, self.

82
00:07:17,820 --> 00:07:23,970
This is actually a key word using Python and other programming languages like Java.

83
00:07:24,000 --> 00:07:33,840
You have this now coming back to this where we define our attributes and then we've added one extra

84
00:07:33,870 --> 00:07:35,850
argument in all our functions.

85
00:07:37,290 --> 00:07:44,370
Now the reason why we're doing this is because we want to give this class or right to give each object

86
00:07:44,670 --> 00:07:51,720
created based on this class an identity which is going to be different from this other one right here.

87
00:07:52,020 --> 00:07:58,470
So this means that whenever we create this or if we create an object they happy from this class is going

88
00:07:58,470 --> 00:08:01,560
to have a different identity from this other one.

89
00:08:01,830 --> 00:08:09,510
By identity will mean is going to have a different way of working with this functions or methods.

90
00:08:10,050 --> 00:08:12,390
And also the attributes are going to be different.

91
00:08:13,110 --> 00:08:17,580
And this is done simply by using this self.

92
00:08:18,930 --> 00:08:20,850
Now, that said, let's run this.

93
00:08:22,350 --> 00:08:23,970
We see that we have an error.

94
00:08:24,300 --> 00:08:26,130
We thought that a solve is not defined.

95
00:08:26,850 --> 00:08:30,000
Now, the way we solve this is by including a constructor.

96
00:08:30,210 --> 00:08:36,300
So instead of having to put this attribute all the way we've just done, we are going to define a constructor.

97
00:08:36,570 --> 00:08:41,040
And the constructor is just a special type of matter.

98
00:08:41,430 --> 00:08:44,070
So we have this in its method.

99
00:08:44,400 --> 00:08:46,500
This init method is what we call the constructor.

100
00:08:47,010 --> 00:08:48,810
Not that you cannot see.

101
00:08:48,810 --> 00:08:50,130
For example, you cannot do this.

102
00:08:50,130 --> 00:08:53,470
You can just define in there like this and then expect it to work.

103
00:08:53,490 --> 00:09:01,410
So this indeed has to have to double on the cars before and then two on this class after.

104
00:09:01,980 --> 00:09:04,500
So double before and then double after.

105
00:09:04,890 --> 00:09:12,210
Once we have this, now it's in this constructor that would define those attributes for the class or

106
00:09:12,870 --> 00:09:15,420
actually this object attributes.

107
00:09:17,250 --> 00:09:18,510
So now let's run again.

108
00:09:18,810 --> 00:09:20,490
You see that everything works fine now.

109
00:09:20,820 --> 00:09:24,090
And that's simply because this attribute, all right.

110
00:09:24,120 --> 00:09:34,830
Of this class has been defined such that we could now, for every object, define its own attributes.

111
00:09:36,370 --> 00:09:37,780
There's an error here.

112
00:09:38,200 --> 00:09:40,120
We shall skip this.

113
00:09:40,120 --> 00:09:41,680
Like we should just run this for now.

114
00:09:41,950 --> 00:09:42,910
So let's run again.

115
00:09:42,910 --> 00:09:45,970
We see that we have this error and take note.

116
00:09:46,420 --> 00:09:48,630
We must also have the self that's passing in.

117
00:09:48,640 --> 00:09:48,910
Neat.

118
00:09:48,910 --> 00:09:49,990
So let's run again.

119
00:09:49,990 --> 00:09:50,710
And there we go.

120
00:09:50,710 --> 00:09:51,730
It works fine now.

121
00:09:52,510 --> 00:10:03,070
So obviously this is Smile belonged to the class smiley but now this is smile is actually the is smile

122
00:10:03,310 --> 00:10:05,980
for this happy object.

123
00:10:07,290 --> 00:10:13,560
And the way we did this was by using the South and then by including a constructor.

124
00:10:15,010 --> 00:10:16,630
So on that.

125
00:10:17,080 --> 00:10:17,710
That's fine.

126
00:10:17,740 --> 00:10:19,600
Now, let's come back to this or this.

127
00:10:20,020 --> 00:10:20,710
And there we go.

128
00:10:20,740 --> 00:10:25,030
We see that this time around, the code works fine.

129
00:10:25,840 --> 00:10:28,240
But we are having a true instead of a false.

130
00:10:28,360 --> 00:10:30,250
So what do we do to solve this problem?

131
00:10:31,000 --> 00:10:39,460
The simple way we could solve this problem is by instead of saying is smile as if this is smile belonged

132
00:10:39,460 --> 00:10:40,150
to the class.

133
00:10:40,390 --> 00:10:43,400
We have self that is smile.

134
00:10:43,840 --> 00:10:53,140
So that Python knows that this is smile is actually the attribute for this set object.

135
00:10:53,710 --> 00:10:55,000
So let's run again.

136
00:10:55,240 --> 00:10:56,030
And there we go.

137
00:10:56,080 --> 00:10:56,980
Everything works fine.

138
00:10:56,980 --> 00:10:59,260
Now we have this as false.

139
00:10:59,620 --> 00:11:00,760
So sad.

140
00:11:01,330 --> 00:11:06,100
That is smile is false and happy.

141
00:11:06,520 --> 00:11:07,690
That is smile.

142
00:11:09,510 --> 00:11:10,140
It's true.

143
00:11:11,160 --> 00:11:13,200
We could go ahead and modify this again.

144
00:11:13,920 --> 00:11:19,980
Let's suppose we want to do this in a way that undefined in the smile we just see.

145
00:11:19,980 --> 00:11:27,750
For example, we see the past and the status quo is smile status, is smile status.

146
00:11:28,200 --> 00:11:32,580
And then instead of having this status of run this, we have an arrow.

147
00:11:32,610 --> 00:11:41,220
Because normally the way the construct has been defined, we have all we are meant to pass in any value

148
00:11:41,220 --> 00:11:41,820
right here.

149
00:11:43,920 --> 00:11:49,080
So what we do is we're going to have this yeah, we'll see this smile.

150
00:11:50,190 --> 00:11:52,590
So by default, we will set it to true.

151
00:11:53,220 --> 00:11:54,180
By default is true.

152
00:11:55,020 --> 00:11:55,470
So now.

153
00:11:55,470 --> 00:11:57,360
Yeah, we have the smile.

154
00:11:58,140 --> 00:11:59,940
Okay, let's run this again.

155
00:12:01,080 --> 00:12:01,830
And there we go.

156
00:12:02,130 --> 00:12:06,330
We set out without having to explicitly call on the set smile method.

157
00:12:06,630 --> 00:12:10,380
We already have the set turn to false.

158
00:12:10,710 --> 00:12:12,510
All the is smile for set then to false.

159
00:12:12,510 --> 00:12:13,200
Let's take this off.

160
00:12:13,200 --> 00:12:14,700
So you see that it works.

161
00:12:16,140 --> 00:12:16,680
So that's it.

162
00:12:16,920 --> 00:12:20,670
So we see that setter is smiles false because of the way it was defined.

163
00:12:20,970 --> 00:12:25,140
And that was the role of this init function, which is actually a constructor.

164
00:12:25,380 --> 00:12:29,040
So we are constructing this object based on this class.

165
00:12:30,020 --> 00:12:35,480
By already defining a smile in such a way that it is true.

166
00:12:35,840 --> 00:12:39,890
And the case where we have, for example, just happy by default years since we don't pass anything

167
00:12:39,890 --> 00:12:40,880
by default, it's true.

168
00:12:41,210 --> 00:12:45,020
And then when we want it to be false, we have just to specify that I want it to be false.

169
00:12:45,680 --> 00:12:52,580
Now the next step will be to take this and say, okay, this color will repeat for the first color we

170
00:12:52,580 --> 00:12:54,170
set it to default whites.

171
00:12:54,980 --> 00:12:56,780
We do the same for the I color.

172
00:12:57,590 --> 00:12:59,120
We set it to default.

173
00:12:59,180 --> 00:13:00,800
Whites That's it.

174
00:13:01,460 --> 00:13:04,160
So that we then we go, we have the face color.

175
00:13:05,900 --> 00:13:09,350
Yeah, we have the face color around this.

176
00:13:09,950 --> 00:13:11,000
Everything was fine.

177
00:13:11,480 --> 00:13:18,020
Let's now set this face color to see orange.

178
00:13:19,580 --> 00:13:20,180
Orange.

179
00:13:20,900 --> 00:13:24,200
And then we have said, now let's put it in black.

180
00:13:24,200 --> 00:13:25,040
We have a black.

181
00:13:25,160 --> 00:13:30,710
The slight that's a black said the face color.

182
00:13:32,210 --> 00:13:36,450
So on that that we go so we see that now our side is good.

183
00:13:36,740 --> 00:13:41,570
Most of this of print simply print is.

184
00:13:45,230 --> 00:13:45,870
Wrong again.

185
00:13:45,890 --> 00:13:46,360
Okay.

186
00:13:46,370 --> 00:13:48,110
So now we have four black.

187
00:13:48,380 --> 00:13:51,080
And then we could also obviously into the eye color.

188
00:13:52,070 --> 00:13:53,040
Eye color?

189
00:13:53,570 --> 00:13:55,160
No, I closed white.

190
00:13:55,170 --> 00:13:57,350
So just take this will let.

191
00:13:57,830 --> 00:14:01,520
So let's print out now the eye color.

192
00:14:02,720 --> 00:14:06,950
Sad that I actually saw that eye color on it.

193
00:14:07,220 --> 00:14:07,790
There we go.

194
00:14:07,880 --> 00:14:08,840
We have the face.

195
00:14:08,840 --> 00:14:10,670
Got a black, eye color black.

196
00:14:10,670 --> 00:14:12,460
And then this is smiles false.

197
00:14:12,470 --> 00:14:16,010
So this isn't as the smile and smiley.
