1
00:00:05,580 --> 00:00:08,600
in the last video we saw how subclasses

2
00:00:08,600 --> 00:00:10,800
can take advantage of all the attributes

3
00:00:10,800 --> 00:00:13,860
data attributes and methods of their

4
00:00:13,860 --> 00:00:16,830
superclass and we also added extra

5
00:00:16,830 --> 00:00:19,460
functionality to our subclasses to give

6
00:00:19,460 --> 00:00:21,240
them extra attributes that their base

7
00:00:21,240 --> 00:00:24,180
class didn't have in this video we're

8
00:00:24,180 --> 00:00:26,010
going to see how to change the behavior

9
00:00:26,010 --> 00:00:28,710
further so that a subclass can implement

10
00:00:28,710 --> 00:00:31,260
a method from its superclass and

11
00:00:31,260 --> 00:00:33,960
actually do things differently now vampire

12
00:00:33,960 --> 00:00:36,660
are shifty creatures they don't get to

13
00:00:36,660 --> 00:00:38,700
live for all eternity without learning a

14
00:00:38,700 --> 00:00:40,790
few tricks after all so what we're going

15
00:00:40,790 --> 00:00:42,930
to do is change the take damage method

16
00:00:42,930 --> 00:00:46,350
so that vampires can dodge when attacked

17
00:00:46,350 --> 00:00:48,780
can turn into a bat or move super fast

18
00:00:48,780 --> 00:00:51,860
or whatever trick they learnt

19
00:00:51,860 --> 00:00:54,630
to avoid getting bashed so going to

20
00:00:54,630 --> 00:00:56,810
choose a random element so that our

21
00:00:56,810 --> 00:00:59,130
vampire has a one-in-three chance of

22
00:00:59,130 --> 00:01:00,470
dodging a blow

23
00:01:00,470 --> 00:01:02,540
now we've used the random module before

24
00:01:02,540 --> 00:01:04,700
and we're going to use it again here to

25
00:01:04,700 --> 00:01:07,110
generate a random number between one on

26
00:01:07,110 --> 00:01:09,000
the three inclusive and if we get a

27
00:01:09,000 --> 00:01:11,760
three vampires successfully dodges the blow

28
00:01:11,760 --> 00:01:15,720
let's open up the vampire class which is

29
00:01:15,720 --> 00:01:17,250
if you recall is in our enemy.py

30
00:01:17,250 --> 00:01:19,680
script we're going to come down here and

31
00:01:19,680 --> 00:01:24,080
start to make some changes so we're

32
00:01:24,080 --> 00:01:28,050
going to do is start and create the

33
00:01:28,050 --> 00:01:32,070
dodges method so....

34
00:01:32,070 --> 00:01:36,870
....

35
00:01:36,870 --> 00:01:39,300
....

36
00:01:39,300 --> 00:01:45,080
...

37
00:01:45,080 --> 00:02:18,780
...

38
00:02:18,780 --> 00:02:22,110
...so we now

39
00:02:22,110 --> 00:02:24,030
got a method which is quite simple

40
00:02:24,030 --> 00:02:26,370
and if the number generated is three

41
00:02:26,370 --> 00:02:28,050
we're going to print a message that the

42
00:02:28,050 --> 00:02:29,970
vampire Dodges and return true

43
00:02:29,970 --> 00:02:32,820
otherwise it returns false now one

44
00:02:32,820 --> 00:02:34,050
thing you might be wondering is looking

45
00:02:34,050 --> 00:02:37,080
at code is why i imported the random

46
00:02:37,080 --> 00:02:39,840
method on line 43 into this method rather

47
00:02:39,840 --> 00:02:42,030
than putting it at the top of the module

48
00:02:42,030 --> 00:02:44,040
and to be honest I'm actually wondering

49
00:02:44,040 --> 00:02:46,620
that myself and seriously though what i

50
00:02:46,620 --> 00:02:49,470
have done is show you that it can be

51
00:02:49,470 --> 00:02:51,660
done there so you may see it in code

52
00:02:51,660 --> 00:02:53,580
that you have to maintain and in rare

53
00:02:53,580 --> 00:02:56,520
cases it may even make sense to do it

54
00:02:56,520 --> 00:02:57,750
like this

55
00:02:57,750 --> 00:02:59,340
now with that said that most of the time

56
00:02:59,340 --> 00:03:01,770
I suggest you don't do it like this i'm

57
00:03:01,770 --> 00:03:03,210
going to take my own advice and remove the

58
00:03:03,210 --> 00:03:05,670
import to the start of the module we're

59
00:03:05,670 --> 00:03:10,950
it belongs ok write at to the top there

60
00:03:10,950 --> 00:03:17,640
ok so we now defined the Dodges

61
00:03:17,640 --> 00:03:20,400
method for the vampire added an extra

62
00:03:20,400 --> 00:03:22,200
few lines their just for clarity with

63
00:03:22,200 --> 00:03:24,780
subtitles but i'll remove that too at

64
00:03:24,780 --> 00:03:25,650
some point

65
00:03:25,650 --> 00:03:28,170
alright so that's better at this point

66
00:03:28,170 --> 00:03:30,810
we now no longer import the random module

67
00:03:30,810 --> 00:03:33,530
every time the Dodge method is called and

68
00:03:33,530 --> 00:03:34,800
if we need to use random numbers in

69
00:03:34,800 --> 00:03:36,900
another enemy class object it's now

70
00:03:36,900 --> 00:03:40,310
available to all the adventure games are

71
00:03:40,310 --> 00:03:42,600
traditionally played with dice so we

72
00:03:42,600 --> 00:03:43,950
will most certainly want to include

73
00:03:43,950 --> 00:03:46,890
random behavior elsewhere and even if we knew

74
00:03:46,890 --> 00:03:48,810
we only ever use the random module

75
00:03:48,810 --> 00:03:50,610
the Dodge method it's still not a good

76
00:03:50,610 --> 00:03:52,650
idea to perform the import their

77
00:03:52,650 --> 00:03:54,660
alright so now we're going to change the

78
00:03:54,660 --> 00:03:57,690
behavior of our vampires when their

79
00:03:57,690 --> 00:03:59,840
attacked but before we do that let's

80
00:03:59,840 --> 00:04:01,710
swing back over to the main python script

81
00:04:01,710 --> 00:04:04,860
and test our dodged method so

82
00:04:04,860 --> 00:04:07,170
we're going to put some code down here

83
00:04:07,170 --> 00:04:09,790
so before line 28

84
00:04:09,790 --> 00:04:14,020
we're going to put....

85
00:04:14,020 --> 00:04:19,570
....

86
00:04:19,570 --> 00:04:22,930
....

87
00:04:22,930 --> 00:04:26,500
...

88
00:04:26,500 --> 00:04:28,000
so lets just run this to see that it does work

89
00:04:28,000 --> 00:04:33,940
we can see if we scroll up that vlads

90
00:04:33,940 --> 00:04:36,400
doggers I think it should fix that

91
00:04:36,400 --> 00:04:40,330
dodges that is better try that

92
00:04:40,330 --> 00:04:42,610
again and we should see now that vlad our

93
00:04:42,610 --> 00:04:45,520
vampires should randomly dodge

94
00:04:45,520 --> 00:04:48,910
dodge there and it's a

95
00:04:48,910 --> 00:04:52,270
one-in-three chance just run it one more time

96
00:04:52,270 --> 00:04:57,700
theirs another dodge so we can say

97
00:04:57,700 --> 00:04:59,320
that we are getting different results it is

98
00:04:59,320 --> 00:05:01,030
random and we can see that vlad our

99
00:05:01,030 --> 00:05:03,190
vampire is dodging some of the attacks

100
00:05:03,190 --> 00:05:05,920
so it does seem to be working we saw

101
00:05:05,920 --> 00:05:07,510
that the last time I run it there

102
00:05:07,510 --> 00:05:09,190
the Dodges came up less i think there's

103
00:05:09,190 --> 00:05:11,320
any actually one dodge there for the

104
00:05:11,320 --> 00:05:13,240
whole run and you will find situations

105
00:05:13,240 --> 00:05:15,700
because it's random where that vlad

106
00:05:15,700 --> 00:05:18,370
won't dodge at all and it's also possible

107
00:05:18,370 --> 00:05:20,350
for him to dodge every blow and never die

108
00:05:20,350 --> 00:05:22,990
but it's actually not very likely

109
00:05:22,990 --> 00:05:24,970
alright so we've added a new method to

110
00:05:24,970 --> 00:05:26,440
the vampire class to give them the

111
00:05:26,440 --> 00:05:29,140
ability to dodge what we really want is

112
00:05:29,140 --> 00:05:30,850
for that behavior to be built into the

113
00:05:30,850 --> 00:05:33,070
class rather than our main program

114
00:05:33,070 --> 00:05:34,810
having to check that during each attack

115
00:05:34,810 --> 00:05:37,570
so to do that we're going to override

116
00:05:37,570 --> 00:05:38,320
the take

117
00:05:38,320 --> 00:05:40,630
_damage method that the vampire

118
00:05:40,630 --> 00:05:43,750
class inherits from enemy now don't

119
00:05:43,750 --> 00:05:46,390
confuse overriding a method with

120
00:05:46,390 --> 00:05:48,580
overloading it as i mentioned earlier

121
00:05:48,580 --> 00:05:52,150
overloading doesn't exist in python so

122
00:05:52,150 --> 00:05:53,590
if you're not sure what it is then don't

123
00:05:53,590 --> 00:05:55,390
worry because you can't actually do it

124
00:05:55,390 --> 00:05:58,600
anyway but overriding a method that

125
00:05:58,600 --> 00:06:01,870
means replacing it with another one now

126
00:06:01,870 --> 00:06:04,630
in languages such as Java and C++ there

127
00:06:04,630 --> 00:06:07,150
are restrictions on the definition of an

128
00:06:07,150 --> 00:06:10,330
overriding method in Python you just write

129
00:06:10,330 --> 00:06:12,370
a new method with the same name as the

130
00:06:12,370 --> 00:06:14,380
one that you want to override the new

131
00:06:14,380 --> 00:06:15,520
method doesn't even have to have the

132
00:06:15,520 --> 00:06:17,470
same or accept the same number of

133
00:06:17,470 --> 00:06:21,310
parameters although it usually will so

134
00:06:21,310 --> 00:06:23,550
lets override the enemy

135
00:06:23,550 --> 00:06:25,660
classes take damage method to make

136
00:06:25,660 --> 00:06:27,600
it do something different in the vampire

137
00:06:27,600 --> 00:06:32,010
class going to come up and work on our

138
00:06:32,010 --> 00:06:33,420
vampire class and what we're going to do

139
00:06:33,420 --> 00:06:35,070
is come down here and add another

140
00:06:35,070 --> 00:06:40,860
method we're going to type...

141
00:06:40,860 --> 00:06:42,390
...

142
00:06:42,390 --> 00:06:49,540
...

143
00:06:49,540 --> 00:06:52,350
....

144
00:06:52,350 --> 00:06:54,480
...

145
00:06:54,480 --> 00:06:56,220
...

146
00:06:56,220 --> 00:06:58,770
...let's just run it like I have

147
00:06:58,770 --> 00:07:01,660
defined it on line 52 and see what

148
00:07:01,660 --> 00:07:07,920
happens when I run it and see we

149
00:07:07,920 --> 00:07:08,520
can get

150
00:07:08,520 --> 00:07:10,050
or we are getting into an infinite loop so

151
00:07:10,050 --> 00:07:14,850
i want to stop the program so let's

152
00:07:14,850 --> 00:07:15,850
actually go back and look at what

153
00:07:15,850 --> 00:07:20,100
happened now in our main py script we

154
00:07:20,100 --> 00:07:21,850
keep on looping as long as the vamp is

155
00:07:21,850 --> 00:07:25,450
alive on line 27 that method the method

156
00:07:25,450 --> 00:07:27,270
that can result in an enemy no longer

157
00:07:27,270 --> 00:07:29,410
being alive is the take_damage

158
00:07:29,410 --> 00:07:32,260
method in the enemy class so when our

159
00:07:32,260 --> 00:07:35,040
vampire object use that method which

160
00:07:35,040 --> 00:07:36,850
they inherit from enemy the program

161
00:07:36,850 --> 00:07:39,510
works but now that we've given the

162
00:07:39,510 --> 00:07:41,850
vampire class its own take_

163
00:07:41,850 --> 00:07:43,980
damage method that's the method being

164
00:07:43,980 --> 00:07:47,010
called up here on line 29 the new method

165
00:07:47,010 --> 00:07:49,570
that we defined for the vampire now

166
00:07:49,570 --> 00:07:51,030
because the vampire version of the

167
00:07:51,030 --> 00:07:52,690
method doesn't do anything yet

168
00:07:52,690 --> 00:07:55,260
therefore our vampire never dies now

169
00:07:55,260 --> 00:07:56,850
that may be a feature of vampires but

170
00:07:56,850 --> 00:07:58,260
it's going to make for a very boring

171
00:07:58,260 --> 00:08:01,470
game but it does show now that we

172
00:08:01,470 --> 00:08:03,210
are calling the vampire class take_damage

173
00:08:03,210 --> 00:08:06,030
method rather than the enemy

174
00:08:06,030 --> 00:08:07,920
one it really does confirm that that method

175
00:08:07,920 --> 00:08:09,330
is being executed and not the original

176
00:08:09,330 --> 00:08:11,820
take_damage method from the

177
00:08:11,820 --> 00:08:13,380
superclass which in this case

178
00:08:13,380 --> 00:08:15,990
was the enemy class that's why i ran it

179
00:08:15,990 --> 00:08:17,200
at this stage just to make that clear

180
00:08:17,200 --> 00:08:20,100
but what we want to do here is call the super

181
00:08:20,100 --> 00:08:22,630
version of take damage but change things

182
00:08:22,630 --> 00:08:25,110
slightly so that our vampires can still

183
00:08:25,110 --> 00:08:27,510
dodge now we've already seen how to call

184
00:08:27,510 --> 00:08:30,360
a super method from a subclass when we

185
00:08:30,360 --> 00:08:32,440
created the init method for the troll

186
00:08:32,440 --> 00:08:34,710
and vampire classes so now we can do the

187
00:08:34,710 --> 00:08:37,320
same thing for take_damage

188
00:08:37,320 --> 00:08:39,740
we only want to take damage if the

189
00:08:39,740 --> 00:08:41,990
vampire doesn't dodge so let's write the

190
00:08:41,990 --> 00:08:44,780
code for that so going back to our enemy

191
00:08:44,780 --> 00:08:47,660
class to our vampire class whether i'm

192
00:08:47,660 --> 00:08:50,430
going to get rid of this pass instead what

193
00:08:50,430 --> 00:08:52,680
we're going to put in here is....

194
00:08:52,680 --> 00:08:58,160
....

195
00:08:58,160 --> 00:09:03,570
...

196
00:09:03,570 --> 00:09:08,130
...so we are using super just like we did

197
00:09:08,130 --> 00:09:10,380
when we call these superclasses init

198
00:09:10,380 --> 00:09:13,770
method you can see that on line 43 only

199
00:09:13,770 --> 00:09:15,510
this time we are calling the take_

200
00:09:15,510 --> 00:09:18,210
damage method now by calling take_

201
00:09:18,210 --> 00:09:20,310
damage like this we don't to write all

202
00:09:20,310 --> 00:09:22,770
the code again we just wrap the call

203
00:09:22,770 --> 00:09:25,220
to the super method in a test to see

204
00:09:25,220 --> 00:09:27,180
whether the vampire dodges or should

205
00:09:27,180 --> 00:09:29,850
take damage the other advantage is now

206
00:09:29,850 --> 00:09:31,260
we don't need to put the testing in our

207
00:09:31,260 --> 00:09:34,890
main program let's put that back so we

208
00:09:34,890 --> 00:09:36,470
can take out this if not vamped

209
00:09:36,470 --> 00:09:41,030
Dodges now back to what it was and i

210
00:09:41,030 --> 00:09:43,500
just comment that out of print for now

211
00:09:43,500 --> 00:09:46,770
if we run this we should see that it

212
00:09:46,770 --> 00:09:50,220
works vlad is down eventually

213
00:09:50,220 --> 00:09:51,870
and his got heaps dodging you can see these

214
00:09:51,870 --> 00:09:53,760
are quire a few Dodges this time this

215
00:09:53,760 --> 00:09:56,190
particular occasion is taking damage as

216
00:09:56,190 --> 00:09:58,260
well and then he is dead and he's now dead on

217
00:09:58,260 --> 00:10:00,650
the last line and again because of the

218
00:10:00,650 --> 00:10:02,550
random element the number of Dodges each

219
00:10:02,550 --> 00:10:05,070
time will vary greatly but over time it

220
00:10:05,070 --> 00:10:06,720
should be roughly one-third of each

221
00:10:06,720 --> 00:10:08,880
attack that results in a successful

222
00:10:08,880 --> 00:10:12,530
dodge now note that vlad sometimes starts off

223
00:10:12,530 --> 00:10:14,660
with all 12 hit points because you

224
00:10:14,660 --> 00:10:16,500
sometimes dodge the attack when we

225
00:10:16,500 --> 00:10:18,210
attempt to take five points of damage

226
00:10:18,210 --> 00:10:20,760
here on line 20 so in other words the

227
00:10:20,760 --> 00:10:22,440
ability to dodge is now part of the

228
00:10:22,440 --> 00:10:25,560
vampire subclass and although

229
00:10:25,560 --> 00:10:27,750
vampires inherit from enemy they

230
00:10:27,750 --> 00:10:29,760
now behave differently when attacked

231
00:10:29,760 --> 00:10:32,720
so you've now seen two of the really

232
00:10:32,720 --> 00:10:34,380
important benefits of using inheritance

233
00:10:34,380 --> 00:10:38,400
when creating classes first our sub

234
00:10:38,400 --> 00:10:40,080
classes get all the attributes that's

235
00:10:40,080 --> 00:10:42,530
the data and methods that are defined in

236
00:10:42,530 --> 00:10:44,430
their base class also known as a

237
00:10:44,430 --> 00:10:46,890
superclass so that we don't have to

238
00:10:46,890 --> 00:10:49,160
write the same code again and again for

239
00:10:49,160 --> 00:10:50,320
each sub class

240
00:10:50,320 --> 00:10:53,970
but second we can also extend or alter

241
00:10:53,970 --> 00:10:56,470
the behavior of a class by creating a

242
00:10:56,470 --> 00:10:59,650
subclass that adds extra methods or

243
00:10:59,650 --> 00:11:01,660
changes the behavior of an existing

244
00:11:01,660 --> 00:11:04,030
method we're going to see an example of

245
00:11:04,030 --> 00:11:05,830
that in the next section when we

246
00:11:05,830 --> 00:11:08,710
subclass the TK inter ist box so that

247
00:11:08,710 --> 00:11:10,660
it populates itself with data from a

248
00:11:10,660 --> 00:11:13,530
database now there's one other thing we

249
00:11:13,530 --> 00:11:15,550
might want to do with our classes and

250
00:11:15,550 --> 00:11:17,560
in fact if we were going to do this then

251
00:11:17,560 --> 00:11:19,390
we should have done from the start

252
00:11:19,390 --> 00:11:20,950
however i left the two now because if

253
00:11:20,950 --> 00:11:22,630
you do then you might have a problem

254
00:11:22,630 --> 00:11:25,210
with IntelliJ is renaming of variables

255
00:11:25,210 --> 00:11:27,660
so to see what the potential problem is

256
00:11:27,660 --> 00:11:30,940
we look at the code here what i'm going to do

257
00:11:30,940 --> 00:11:32,910
is I'm just going to comment out these

258
00:11:32,910 --> 00:11:38,910
first two lines and i'm going to put

259
00:11:38,910 --> 00:11:41,500
another line of code in here....

260
00:11:41,500 --> 00:11:43,410
...

261
00:11:43,410 --> 00:11:49,330
...

262
00:11:49,330 --> 00:11:53,260
....you can see here that I've

263
00:11:53,260 --> 00:11:55,530
added some code that modified vlad lives

264
00:11:55,530 --> 00:11:58,570
and hit points attributes directly if

265
00:11:58,570 --> 00:12:03,460
you run this and surprisingly vlads ends

266
00:12:03,460 --> 00:12:05,910
up with no lives left and hit points

267
00:12:05,910 --> 00:12:08,470
set to only one that's normal behavior

268
00:12:08,470 --> 00:12:10,900
for python and as we've seen a few times

269
00:12:10,900 --> 00:12:13,270
we can't prevent code from accessing the

270
00:12:13,270 --> 00:12:16,240
data attributes of our classes what we

271
00:12:16,240 --> 00:12:18,520
can do is providing indication

272
00:12:18,520 --> 00:12:20,970
that this shouldn't be done and if you

273
00:12:20,970 --> 00:12:23,350
remember the convention is to prefix the

274
00:12:23,350 --> 00:12:26,350
attribute names with an underscore now

275
00:12:26,350 --> 00:12:27,880
ideally we would have done this right from

276
00:12:27,880 --> 00:12:30,720
the start and in fact of i'd recommend

277
00:12:30,720 --> 00:12:32,910
prefixing your class data attributes with

278
00:12:32,910 --> 00:12:35,620
an underscore right away if you decide you

279
00:12:35,620 --> 00:12:37,630
want that to you want to hide them and

280
00:12:37,630 --> 00:12:39,220
if you do find that you need to access

281
00:12:39,220 --> 00:12:41,740
them directly you can refactor the ones

282
00:12:41,740 --> 00:12:43,900
that do require direct access or at a

283
00:12:43,900 --> 00:12:45,640
property for them as we saw in a

284
00:12:45,640 --> 00:12:47,080
previous video in this section of the

285
00:12:47,080 --> 00:12:49,900
course so the decision on whether to

286
00:12:49,900 --> 00:12:52,630
hide the attributes or not isn't

287
00:12:52,630 --> 00:12:54,600
necessarily a simple one and there

288
00:12:54,600 --> 00:12:56,320
really are no hard and fast rules that

289
00:12:56,320 --> 00:12:58,410
apply to all scenarios

290
00:12:58,410 --> 00:13:00,100
now keep in mind that the python

291
00:13:00,100 --> 00:13:02,020
philosophy is that you probably

292
00:13:02,020 --> 00:13:03,250
shouldn't hide them

293
00:13:03,250 --> 00:13:06,040
unless modifying them directly will break your

294
00:13:06,040 --> 00:13:08,890
code somehow so modifying the lives

295
00:13:08,890 --> 00:13:10,300
and hit points as we're doing here

296
00:13:10,300 --> 00:13:14,260
on line 31 and 32 won't break the code

297
00:13:14,260 --> 00:13:17,620
so i'd be tempted to leave them as they

298
00:13:17,620 --> 00:13:19,690
were but as I want to show you a

299
00:13:19,690 --> 00:13:21,580
potential pitfall with renaming

300
00:13:21,580 --> 00:13:23,770
attributes in IntelliJ we'll go ahead

301
00:13:23,770 --> 00:13:25,750
and mark them as private for one of a

302
00:13:25,750 --> 00:13:28,060
better term when I use the term private

303
00:13:28,060 --> 00:13:29,500
in Python remember i'm talking about

304
00:13:29,500 --> 00:13:32,650
intention and things aren't really private

305
00:13:32,650 --> 00:13:33,940
alright so we can just go ahead and

306
00:13:33,940 --> 00:13:35,860
refactor our attributes in the enemy

307
00:13:35,860 --> 00:13:40,000
class go back to enemy going up here

308
00:13:40,000 --> 00:13:41,200
because it's the enemy class that we

309
00:13:41,200 --> 00:13:43,180
wanted do our reflecting on going to

310
00:13:43,180 --> 00:13:45,490
start here with a self.name so

311
00:13:45,490 --> 00:13:47,920
going to right click on name refactor

312
00:13:47,920 --> 00:13:51,880
rename just going to add an underscore

313
00:13:51,880 --> 00:13:55,810
to the name press enter so changes

314
00:13:55,810 --> 00:13:59,080
reflected and going to the same for

315
00:13:59,080 --> 00:14:01,660
hitpoints lives and the life

316
00:14:01,660 --> 00:14:04,840
so each one i'm just going to rename just

317
00:14:04,840 --> 00:14:13,660
putting _ at the start

318
00:14:13,660 --> 00:14:22,120
alright so that's all 4 now you can

319
00:14:22,120 --> 00:14:24,580
see here as an example self dot

320
00:14:24,580 --> 00:14:26,770
underscore hit_points equals

321
00:14:26,770 --> 00:14:28,720
remaining points as an example of what

322
00:14:28,720 --> 00:14:30,250
intelliJ has done when it's refactored

323
00:14:30,250 --> 00:14:32,620
and renamed things for us so switching

324
00:14:32,620 --> 00:14:35,740
back to main we can see here that the

325
00:14:35,740 --> 00:14:37,600
attributes have been renamed as well so

326
00:14:37,600 --> 00:14:39,100
intelliJ done that when we use

327
00:14:39,100 --> 00:14:44,710
the refactor but eventually run this we

328
00:14:44,710 --> 00:14:47,440
actually get an error troll object has

329
00:14:47,440 --> 00:14:50,920
no attribute name so intelliJ

330
00:14:50,920 --> 00:14:53,080
normally does a great job but it does

331
00:14:53,080 --> 00:14:54,910
fall down on those replacement fields

332
00:14:54,910 --> 00:14:57,160
that we've used before in the enemy

333
00:14:57,160 --> 00:14:58,240
class in our underscore underscore

334
00:14:58,240 --> 00:15:02,980
string method this method here and

335
00:15:02,980 --> 00:15:04,900
going back to the error

336
00:15:04,900 --> 00:15:06,280
luckily it's actually telling us its

337
00:15:06,280 --> 00:15:08,770
line 27 in the underscore underscore

338
00:15:08,770 --> 00:15:10,960
string underscore underscore method so

339
00:15:10,960 --> 00:15:12,730
we have a look at that again that is

340
00:15:12,730 --> 00:15:14,620
this line here so you can see what the

341
00:15:14,620 --> 00:15:16,360
problem is that intelliJ hasn't

342
00:15:16,360 --> 00:15:18,220
actually rename those replacement fields

343
00:15:18,220 --> 00:15:20,650
correctly now we could just edit up those

344
00:15:20,650 --> 00:15:23,200
occurrences manually but we've also got

345
00:15:23,200 --> 00:15:25,450
to change lines in some other places as

346
00:15:25,450 --> 00:15:27,550
well like for example on line 21 and

347
00:15:27,550 --> 00:15:30,160
line 23 they are both referring to the old

348
00:15:30,160 --> 00:15:31,690
name before it was prefixed with an _

349
00:15:31,690 --> 00:15:33,610
so it's really a bit of work to

350
00:15:33,610 --> 00:15:35,830
do here and going down looking at the

351
00:15:35,830 --> 00:15:37,510
troll we've actually got will

352
00:15:37,510 --> 00:15:38,860
need to do some working there as well the

353
00:15:38,860 --> 00:15:41,110
troll grunt method hasn't an _

354
00:15:41,110 --> 00:15:43,810
for the data attributes anymore either

355
00:15:43,810 --> 00:15:45,490
so quite a bit of work to actually go

356
00:15:45,490 --> 00:15:47,320
right through and refactor this if we

357
00:15:47,320 --> 00:15:49,570
wanted to do it so it's quite a lot of

358
00:15:49,570 --> 00:15:51,940
work and as I mentioning to do this and

359
00:15:51,940 --> 00:15:53,830
I want to draw your attention to a

360
00:15:53,830 --> 00:15:56,530
possible pitfall with refactoring data

361
00:15:56,530 --> 00:15:58,600
attributes but i'm going to show you a

362
00:15:58,600 --> 00:16:01,570
quick way to do with that next important

363
00:16:01,570 --> 00:16:03,160
thing here is that you can get problems

364
00:16:03,160 --> 00:16:04,540
if you use this form of replacement

365
00:16:04,540 --> 00:16:07,000
fields and then try to refactor the

366
00:16:07,000 --> 00:16:09,190
attributes later alright so i'm going to

367
00:16:09,190 --> 00:16:11,140
end the video here now in the next video

368
00:16:11,140 --> 00:16:12,100
will continue on and we're actually

369
00:16:12,100 --> 00:16:14,140
going to bring some regular expressions

370
00:16:14,140 --> 00:16:16,540
to try and fix this issue so see you in

371
00:16:16,540 --> 00:16:22,110
the next video

