1
00:00:02,800 --> 00:00:03,670
Hello everyone.

2
00:00:03,670 --> 00:00:09,220
Welcome to this new session and this session we will learn a few more important concepts of Forbes.

3
00:00:09,220 --> 00:00:14,470
If you'll notice in the last session we never used a student name anywhere student name is an important

4
00:00:14,470 --> 00:00:16,470
property that should be included.

5
00:00:16,540 --> 00:00:20,740
So we should have to rename property but we do not include it anywhere.

6
00:00:21,220 --> 00:00:22,330
Why we not included.

7
00:00:22,330 --> 00:00:24,130
Because there is a reason behind it.

8
00:00:24,520 --> 00:00:27,430
So now let's see how we will work on name.

9
00:00:27,430 --> 00:00:28,020
Okay.

10
00:00:28,030 --> 00:00:36,880
So let us create a class a student so let's create a class student.

11
00:00:36,900 --> 00:00:42,090
Now this time I will have two private properties a general number so each will be integer

12
00:00:46,430 --> 00:00:48,820
age will be integer and is a private property.

13
00:00:48,830 --> 00:00:50,690
Now the name will be a string.

14
00:00:50,810 --> 00:00:57,220
So for storing this string we will use a connectivity took our name and letter to the sizes entered.

15
00:00:57,360 --> 00:00:58,160
Okay.

16
00:00:58,460 --> 00:01:00,840
So we should not do this.

17
00:01:00,910 --> 00:01:01,440
Why.

18
00:01:01,490 --> 00:01:03,920
Because now we have started dynamic allocation.

19
00:01:03,920 --> 00:01:06,450
So now we know how to create data dynamically.

20
00:01:06,540 --> 00:01:12,890
So we should not create that is strategically so creating that dynamically index is very simple CAST

21
00:01:12,900 --> 00:01:17,660
OUR NAME IS NEW.

22
00:01:17,860 --> 00:01:18,730
Hundred.

23
00:01:18,820 --> 00:01:19,560
Okay.

24
00:01:19,840 --> 00:01:25,250
So the problem here is there is a problem here and the problem here is that we do not know the size

25
00:01:25,250 --> 00:01:26,230
of the student name.

26
00:01:26,380 --> 00:01:29,150
If it is more than handed then we will be bribed.

27
00:01:29,320 --> 00:01:33,060
If it is less than a hundred then a lot of memory will be wasted.

28
00:01:33,070 --> 00:01:33,600
Okay.

29
00:01:33,700 --> 00:01:37,690
So according to the requirement we will decide the size of the student name.

30
00:01:37,690 --> 00:01:40,180
So for now let's make it a character pointer.

31
00:01:40,900 --> 00:01:41,140
Okay.

32
00:01:41,140 --> 00:01:44,170
So let's make it a character pointer only.

33
00:01:44,370 --> 00:01:48,400
And according to the requirement we will allocate sites.

34
00:01:48,660 --> 00:01:57,450
So now let's create a constructor so the constructor will take two inputs each and lumber.

35
00:01:57,490 --> 00:02:00,140
We are constructing a betterment based constructor.

36
00:02:00,400 --> 00:02:05,740
So int h.

37
00:02:05,920 --> 00:02:10,350
And secondly B name name.

38
00:02:10,880 --> 00:02:11,160
Okay.

39
00:02:11,190 --> 00:02:19,190
So this arrow h we have to use this here because we have to differentiate between the barometer and

40
00:02:19,190 --> 00:02:21,680
the proper barometer and the property agent.

41
00:02:21,680 --> 00:02:30,820
So this shadow reaches age and similarly this add on name is name.

42
00:02:30,820 --> 00:02:38,620
Okay so what constructor is ready now let us create our display function so that we can print so display

43
00:02:41,440 --> 00:02:43,610
so display function.

44
00:02:43,610 --> 00:02:46,940
Let us first bring the value of Nim.

45
00:02:47,060 --> 00:02:49,040
First we had printing the name of the student.

46
00:02:49,100 --> 00:02:56,990
And then we will print the age of the student Okay so now let us create objects

47
00:02:59,920 --> 00:03:01,100
so a student S1.

48
00:03:01,510 --> 00:03:03,580
So is this treatment right or wrong.

49
00:03:03,580 --> 00:03:04,400
So this is wrong.

50
00:03:04,400 --> 00:03:04,980
Why.

51
00:03:04,990 --> 00:03:11,680
Because as soon as we clear the better based constructor then build constructor in both default constructor

52
00:03:11,800 --> 00:03:14,090
is not visible to us anymore.

53
00:03:14,140 --> 00:03:20,140
So this line what it will do it we tried to call inbuilt default constructor and that constructor is

54
00:03:20,140 --> 00:03:23,000
not visible so this line will throw at it.

55
00:03:23,010 --> 00:03:23,510
Okay.

56
00:03:23,620 --> 00:03:25,280
So what we have to do.

57
00:03:25,360 --> 00:03:25,620
Okay.

58
00:03:25,630 --> 00:03:30,950
So first let us create a name a String name.

59
00:03:31,060 --> 00:03:40,990
So can name let's say the name is let's the name is ABC and now let us create a student.

60
00:03:41,020 --> 00:03:50,370
So student is when we have to call parameters constructor let's say that age is 20 and the name is name.

61
00:03:50,390 --> 00:03:50,900
Okay.

62
00:03:51,020 --> 00:03:53,220
So now let us call display function.

63
00:03:53,240 --> 00:03:54,800
So S1 dart display

64
00:03:59,200 --> 00:04:02,310
Okay now that does create.

65
00:04:02,870 --> 00:04:11,260
Okay so now let us change the value of names so let us make the name ABC.

66
00:04:11,270 --> 00:04:14,090
So now the name is ABC.

67
00:04:14,180 --> 00:04:16,400
Now we will create the object.

68
00:04:16,790 --> 00:04:20,390
So student let's name it as two.

69
00:04:20,540 --> 00:04:25,780
So that ages party and the name is name.

70
00:04:25,820 --> 00:04:26,610
Okay.

71
00:04:26,720 --> 00:04:29,420
So now let us call display function

72
00:04:34,990 --> 00:04:35,680
okay.

73
00:04:35,990 --> 00:04:40,350
So if you will run this file what will be our output.

74
00:04:40,460 --> 00:04:41,060
So let's see

75
00:04:46,930 --> 00:04:55,120
so for student S1 name is ABC and ages 20 for students to name is ABC and the ages 30.

76
00:04:55,170 --> 00:04:55,610
Okay.

77
00:04:55,720 --> 00:04:58,060
So this was our expected output.

78
00:04:58,060 --> 00:05:00,200
So there's is nothing new here.

79
00:05:00,280 --> 00:05:06,940
Now what if after printing as to what if after printing as true I am again printing the value of S1.

80
00:05:06,940 --> 00:05:11,800
So what will happen find out dart display function.

81
00:05:11,850 --> 00:05:15,280
Output should be ABC and 20.

82
00:05:15,280 --> 00:05:19,920
Now let's see what do we output.

83
00:05:20,070 --> 00:05:21,990
See there is something wrong.

84
00:05:22,030 --> 00:05:24,680
The output should be the name should be ABC.

85
00:05:25,150 --> 00:05:29,360
But the output is coming out to be ABC okay.

86
00:05:29,380 --> 00:05:30,630
So why is it so.

87
00:05:30,680 --> 00:05:35,220
Let us try to understand what is going good let us analyse what we have done.

88
00:05:42,610 --> 00:05:42,860
Okay.

89
00:05:42,870 --> 00:05:45,010
So what is the effect of this line.

90
00:05:45,060 --> 00:05:45,900
What it will do.

91
00:05:45,900 --> 00:05:55,010
It will create 80 ABC days and then and let's say that those of the 0 10 Nexus 7 ended okay.

92
00:05:55,090 --> 00:06:05,700
So at this line will happen as friend art student name is 20 and it's already ages 20 and name will

93
00:06:05,700 --> 00:06:06,500
be 700.

94
00:06:06,540 --> 00:06:12,110
We all know how good it bad is our past in fact how it is passed we will pass the test of those Littleton

95
00:06:12,160 --> 00:06:16,460
six so seven and I will go from here and that this line what will happen.

96
00:06:16,620 --> 00:06:22,840
So age is 20 and name is 700.

97
00:06:22,910 --> 00:06:25,310
Okay so this is the scenario ahead.

98
00:06:25,560 --> 00:06:27,330
Now what will S1 contain.

99
00:06:27,390 --> 00:06:37,380
So for the S1 age will become 20 and the name which is a character pointer it stores 700 okay too.

100
00:06:37,410 --> 00:06:38,410
This is the scenario.

101
00:06:38,430 --> 00:06:45,240
S1 so basically what is happening here is so the name is pointing towards this name.

102
00:06:45,260 --> 00:06:51,830
Okay so the name of S1 the character pointer is pointing towards this name.

103
00:06:51,900 --> 00:06:55,420
Okay now add this line as our display.

104
00:06:55,500 --> 00:06:56,610
What it will do.

105
00:06:56,610 --> 00:06:59,310
It will print the name and age.

106
00:06:59,310 --> 00:07:00,960
So for name it what it will do.

107
00:07:00,960 --> 00:07:02,760
It will go to the 700.

108
00:07:02,850 --> 00:07:07,020
So we will reach at best seven hundred and then we will print the entire contents of the array which

109
00:07:07,020 --> 00:07:08,330
is a b c d.

110
00:07:08,620 --> 00:07:10,310
So here it is our output.

111
00:07:10,450 --> 00:07:14,630
So output is a b c v and they just run T.

112
00:07:14,680 --> 00:07:20,480
Okay so now what we did here is we changed the target index and now it becomes E.

113
00:07:20,490 --> 00:07:24,160
So ABC e it is now ABC.

114
00:07:24,360 --> 00:07:24,870
Okay.

115
00:07:25,020 --> 00:07:27,610
And here how we will call.

116
00:07:27,630 --> 00:07:37,200
We will call as to dart student so that ages party and addresses 700 similarly agent names will become

117
00:07:37,260 --> 00:07:39,010
20 and set 20.

118
00:07:39,070 --> 00:07:41,350
Sorry it will -- had 700.

119
00:07:41,520 --> 00:07:43,990
And finally S2 will look something like this.

120
00:07:44,010 --> 00:07:49,650
Ages 30 and S2 name also contains the address 700.

121
00:07:49,760 --> 00:07:50,780
Okay.

122
00:07:50,940 --> 00:07:58,570
It also contains that best 700 and this is our S2 so as to is also pointing towards this area only then

123
00:07:58,660 --> 00:08:00,300
we will print the value of S2.

124
00:08:00,400 --> 00:08:07,150
So for printing the name we will go to our number 700 and print its content so the content is ABC and

125
00:08:07,150 --> 00:08:08,520
they just 30.

126
00:08:08,800 --> 00:08:16,690
Now again we are printing S1 s under display so for us on our display we will do each S1 for printing

127
00:08:16,690 --> 00:08:17,130
the name.

128
00:08:17,140 --> 00:08:18,170
What we will do.

129
00:08:18,270 --> 00:08:23,980
We will go to the seven hundred and print the content now editor seven indeed we have ABC.

130
00:08:23,980 --> 00:08:27,720
So ABC will get printed and they each will be 20.

131
00:08:27,760 --> 00:08:30,240
So that's how ABC is coming out to be here.

132
00:08:30,250 --> 00:08:31,450
Which is wrong.

133
00:08:31,450 --> 00:08:33,830
Ideally it should be ABC.

134
00:08:34,780 --> 00:08:39,610
OK so what is happening here is both objects are pointing towards the same area.

135
00:08:39,640 --> 00:08:43,480
If we do change in one object it will reflect in the other object also.

136
00:08:43,750 --> 00:08:49,940
Okay so what we should do we should copy the end that every other then copying the ad does only.

137
00:08:50,020 --> 00:08:54,230
Okay here we are only copying that address seven that is being getting copied.

138
00:08:54,250 --> 00:08:57,740
Ideally what we should do is we should copy that Eddie.

139
00:08:57,820 --> 00:09:02,950
Okay so this copy this copy is called shallow copy.

140
00:09:02,950 --> 00:09:08,080
So what is the meaning of shallow copy shallow copy means copy only the address.

141
00:09:08,080 --> 00:09:10,420
So currently we are doing shallow copy.

142
00:09:10,530 --> 00:09:11,000
Okay.

143
00:09:11,110 --> 00:09:12,690
So whenever we pass Eddie.

144
00:09:12,700 --> 00:09:17,090
So rather than copying the entirety we copy the address of the Zulu index of dairy.

145
00:09:17,110 --> 00:09:25,800
So if we copy the address if we copy the address of Eddie then it is called shallow copy okay.

146
00:09:25,850 --> 00:09:28,820
So now let's see how to fix this problem

147
00:09:31,720 --> 00:09:34,620
see at this line this arrow age is age.

148
00:09:34,630 --> 00:09:35,070
Okay.

149
00:09:35,080 --> 00:09:36,900
So this line is absolutely correct.

150
00:09:36,910 --> 00:09:40,010
Wyatt is correct because age is then digital variable.

151
00:09:40,060 --> 00:09:42,850
So the whole values being getting copied.

152
00:09:42,850 --> 00:09:47,220
But in this case we are only copying the address.

153
00:09:47,740 --> 00:09:53,620
Okay so at a somewhere else and we have only copied the address of the z index of that diary.

154
00:09:53,680 --> 00:09:56,850
So this is called shallow copy.

155
00:09:56,950 --> 00:09:57,610
This is

156
00:10:00,480 --> 00:10:02,030
shallow copy.

157
00:10:02,410 --> 00:10:10,270
I believe we should avoid shallow copy shallow copy means copy only the address of the error a copy

158
00:10:10,270 --> 00:10:12,130
only the address of the area.

159
00:10:12,130 --> 00:10:18,130
So I believe what we should do we should create a new Eddy and then copy the entirety.

160
00:10:18,600 --> 00:10:19,310
Okay.

161
00:10:19,420 --> 00:10:23,280
We should create a new area and then copy the entire content of dairy.

162
00:10:23,380 --> 00:10:28,750
So that is called deep copy so shallow copies

163
00:10:33,530 --> 00:10:36,990
copy only address

164
00:10:39,910 --> 00:10:44,820
often zero index of the area and deep copy is

165
00:10:47,900 --> 00:10:55,630
copy DNA battery not only their address we should copy the entire area.

166
00:10:55,650 --> 00:10:57,210
Now let's see how we really do this

167
00:11:06,530 --> 00:11:10,950
so let us first of all create a new area so that we can copy the entirety.

168
00:11:10,950 --> 00:11:15,810
So we're creating the new areas in Texas like similar to this new cat.

169
00:11:16,280 --> 00:11:22,110
What it will take it will take the size of the eddy size of the this name.

170
00:11:22,330 --> 00:11:26,910
So for calculating the land we have and will function as to get alien.

171
00:11:27,050 --> 00:11:28,440
We will pass it name.

172
00:11:28,460 --> 00:11:33,840
It will give me the name it will give me the size for example the name is ABC.

173
00:11:33,890 --> 00:11:38,890
So listing land as Tierra Leon will give me for ABC SGI really intrigued me food.

174
00:11:39,500 --> 00:11:45,380
So I have to do plus one had Y plus one because we have to also copy the null corrector so for copying

175
00:11:45,380 --> 00:11:47,270
the null corrector I am doing plus one here

176
00:11:50,300 --> 00:11:50,610
okay.

177
00:11:50,630 --> 00:11:53,030
So now we have created a new Eddy.

178
00:11:53,090 --> 00:11:56,210
Now after creating the new Eddy we just have to copy the content.

179
00:11:56,330 --> 00:12:00,020
So for copying the content we have inbuilt function string copy.

180
00:12:00,050 --> 00:12:10,620
So first we have to give their destination and then we have to give the source so the sources name copy

181
00:12:16,490 --> 00:12:17,030
so.

182
00:12:17,120 --> 00:12:19,220
Copy this name into this name.

183
00:12:19,220 --> 00:12:20,180
Copy the content.

184
00:12:20,180 --> 00:12:20,410
Okay.

185
00:12:20,420 --> 00:12:22,180
So content will get copied.

186
00:12:22,190 --> 00:12:23,390
Null will also get copied.

187
00:12:23,420 --> 00:12:23,900
Okay.

188
00:12:23,900 --> 00:12:30,460
Along with content we will also copy the null and void this plus one here because we need one space.

189
00:12:30,470 --> 00:12:33,500
We need one block for copying that also.

190
00:12:33,500 --> 00:12:33,930
Okay.

191
00:12:33,980 --> 00:12:36,300
Now what will happen in this scenario.

192
00:12:36,380 --> 00:12:43,060
So the name dedicated in the mean that was containing there the 700 and the content was initially ABC

193
00:12:43,080 --> 00:12:48,520
the annual then we will call the function we will call constructor.

194
00:12:48,600 --> 00:12:53,040
So for calling the constructors and text will be like as one dot student.

195
00:12:53,250 --> 00:12:57,270
First we will pass the H and then we will pass the name.

196
00:12:57,270 --> 00:12:59,670
So name will be 700.

197
00:12:59,820 --> 00:13:03,540
So the barometer H will contain 20.

198
00:13:03,570 --> 00:13:06,480
And the barometer name will contain 700.

199
00:13:06,510 --> 00:13:07,000
Okay.

200
00:13:07,080 --> 00:13:10,450
So at this line what we are doing we are creating a new 80.

201
00:13:10,530 --> 00:13:15,120
So this name this arrow name what it will do it will create a new Eddy.

202
00:13:15,300 --> 00:13:20,970
And what will the size of the size of that is five Y five because ABC DST ideally will give me four

203
00:13:21,520 --> 00:13:22,830
and null.

204
00:13:23,220 --> 00:13:25,450
So this is four plus one.

205
00:13:25,470 --> 00:13:31,560
So we will get a new every letter that does have those wrote indexes 800 and then we what we are doing

206
00:13:31,620 --> 00:13:33,230
we are copying the content.

207
00:13:33,300 --> 00:13:36,260
So e b c b and.

208
00:13:36,780 --> 00:13:37,040
Okay.

209
00:13:37,050 --> 00:13:43,920
Now this time this arrow name and this arrow name contains 800.

210
00:13:44,060 --> 00:13:44,320
OK.

211
00:13:44,340 --> 00:13:46,220
This item name contains 800.

212
00:13:46,230 --> 00:13:52,890
So in the next step when we change the value of the name ABC when the value of name became ABC.

213
00:13:52,890 --> 00:13:58,290
And then if we again print the value of S1 so that's when name contains at does 800.

214
00:13:58,290 --> 00:13:59,890
So it will print from here.

215
00:14:00,060 --> 00:14:00,930
It will print from here.

216
00:14:00,960 --> 00:14:02,020
So what.

217
00:14:02,160 --> 00:14:03,730
So I would probably be right.

218
00:14:03,750 --> 00:14:05,310
Our output will come out to be right.

219
00:14:05,310 --> 00:14:05,830
ABC.

220
00:14:05,830 --> 00:14:06,560
The only.

221
00:14:06,570 --> 00:14:06,800
OK.

222
00:14:06,810 --> 00:14:09,780
So this is called deep copy.

223
00:14:09,840 --> 00:14:12,320
So what is the procedure for deep copy deep copy space.

224
00:14:12,330 --> 00:14:18,090
Make a new Adi which is same as the size of the this name.

225
00:14:18,090 --> 00:14:19,400
And then copy the content.

226
00:14:19,420 --> 00:14:19,690
Okay.

227
00:14:19,710 --> 00:14:22,750
Make a new Eddie make a new Eddie.

228
00:14:22,780 --> 00:14:25,140
And then copy the content.

229
00:14:25,210 --> 00:14:28,360
So in this way we will solve our problem of shallow copy.

230
00:14:28,360 --> 00:14:29,080
Now let's see.

231
00:14:30,110 --> 00:14:31,710
Okay so let us compile this file

232
00:14:35,620 --> 00:14:35,890
okay.

233
00:14:35,900 --> 00:14:41,810
So this item name is string lint so if we're using the function string England we have to include.

234
00:14:41,820 --> 00:14:44,190
I had a file called C string

235
00:14:51,520 --> 00:14:55,200
Okay so we can see here is now the output is ABC the only.

236
00:14:55,220 --> 00:14:58,850
Okay so this is called shallow copying deep copy.

237
00:14:58,850 --> 00:15:01,100
So I hope you guys understand this.

238
00:15:01,100 --> 00:15:01,430
Okay.

239
00:15:01,460 --> 00:15:01,910
Thank you.
