1
00:00:05,460 --> 00:00:06,900
in the previous video we have a look at

2
00:00:06,900 --> 00:00:09,270
polymorphism and we saw how different

3
00:00:09,270 --> 00:00:11,340
objects can inherit similar behavior

4
00:00:11,340 --> 00:00:14,910
from a common base class so although ints

5
00:00:14,910 --> 00:00:16,920
floats and lists are different types

6
00:00:16,920 --> 00:00:18,800
they can all be printed

7
00:00:18,800 --> 00:00:19,890
that's because they will provide a

8
00:00:19,890 --> 00:00:22,740
string or STR method if a type doesn't

9
00:00:22,740 --> 00:00:25,020
provide a specific implementation of str

10
00:00:25,020 --> 00:00:27,510
string method it ends up

11
00:00:27,510 --> 00:00:29,070
getting inherited from the base object

12
00:00:29,070 --> 00:00:31,950
class so python isn't really interested

13
00:00:31,950 --> 00:00:34,140
in what type something it focus

14
00:00:34,140 --> 00:00:36,900
instead on how things behave so again if

15
00:00:36,900 --> 00:00:39,660
it quacks like a duck it's a duck when

16
00:00:39,660 --> 00:00:41,250
we finish the last video by giving our

17
00:00:41,250 --> 00:00:43,500
penguin class the same methods as the

18
00:00:43,500 --> 00:00:46,440
duck class so that penguin would behave

19
00:00:46,440 --> 00:00:49,470
the same as a duck so inheritance isn't

20
00:00:49,470 --> 00:00:52,110
the only way to implement polymorphism a

21
00:00:52,110 --> 00:00:53,730
class can behave in the same way as

22
00:00:53,730 --> 00:00:55,700
another class as long as it's got the

23
00:00:55,700 --> 00:00:58,860
necessary methods and data attributes so

24
00:00:58,860 --> 00:01:00,750
relating this back to our enemy objects

25
00:01:00,750 --> 00:01:03,840
we can say that a troll is an enemy and a

26
00:01:03,840 --> 00:01:06,540
vampire is an enemy so inheritance

27
00:01:06,540 --> 00:01:09,200
results in a is a relationship and

28
00:01:09,200 --> 00:01:12,560
similarly a penguin is a duck at least

29
00:01:12,560 --> 00:01:14,160
as far as that test_duck

30
00:01:14,160 --> 00:01:16,490
functions concerned so in this video

31
00:01:16,490 --> 00:01:18,300
we're going to start having a look at

32
00:01:18,300 --> 00:01:20,240
two other object orientated terms

33
00:01:20,240 --> 00:01:23,780
composition and aggregation now

34
00:01:23,780 --> 00:01:26,160
composition and aggregation are used when

35
00:01:26,160 --> 00:01:28,280
you have a has a relationship rather

36
00:01:28,280 --> 00:01:31,050
than a is a relationship so if we go

37
00:01:31,050 --> 00:01:33,170
have a bird's wings we wouldn't say that

38
00:01:33,170 --> 00:01:35,810
a duck is a wing would say that duck has

39
00:01:35,810 --> 00:01:37,760
a wing now if you're unsure about

40
00:01:37,760 --> 00:01:39,260
whether you should use inheritance or

41
00:01:39,260 --> 00:01:41,450
not then those two ways of looking at

42
00:01:41,450 --> 00:01:43,580
the relationship will normally make it

43
00:01:43,580 --> 00:01:45,200
obvious whether inheritance is

44
00:01:45,200 --> 00:01:47,840
appropriate or not what I'm going to do is

45
00:01:47,840 --> 00:01:50,330
going back over here now to our duck

46
00:01:50,330 --> 00:01:53,780
.py again I'm just going to comment

47
00:01:53,780 --> 00:01:56,240
at this code at the bottom for new so

48
00:01:56,240 --> 00:01:57,380
what I'll do is I'll comment the

49
00:01:57,380 --> 00:02:00,870
test duck altogether and we'll just

50
00:02:00,870 --> 00:02:02,120
like Donald in will just comment out

51
00:02:02,120 --> 00:02:06,120
percy for now and I'll just delete the call

52
00:02:06,120 --> 00:02:07,830
to test _ ducks so we are just left

53
00:02:07,830 --> 00:02:11,600
now with defining donal alright so

54
00:02:11,600 --> 00:02:13,470
let's add a wing class to the start of a

55
00:02:13,470 --> 00:02:15,390
main file and we are going to give duck

56
00:02:15,390 --> 00:02:17,610
class wings so at the top

57
00:02:17,610 --> 00:02:26,880
here.....

58
00:02:26,880 --> 00:02:29,310
...

59
00:02:29,310 --> 00:02:32,330
...

60
00:02:32,330 --> 00:02:34,320
....

61
00:02:34,320 --> 00:02:38,130
...

62
00:02:38,130 --> 00:03:42,270
...

63
00:03:42,270 --> 00:03:44,460
ok the couple of extra lines to keep intellij
...

64
00:03:44,460 --> 00:03:48,000
happy now this is simplified

65
00:03:48,000 --> 00:03:50,670
slightly so whether wing is capable of

66
00:03:50,670 --> 00:03:53,460
lifting an object such as a duck depends

67
00:03:53,460 --> 00:03:54,660
on things like the weight of the object

68
00:03:54,660 --> 00:03:57,150
the surface area and shape of the wing

69
00:03:57,150 --> 00:04:00,000
and its speed through the air and we

70
00:04:00,000 --> 00:04:01,860
could apply Newton's law and put in the

71
00:04:01,860 --> 00:04:04,440
correct formula to decide if our wings

72
00:04:04,440 --> 00:04:06,180
capable of flying when it's attached to

73
00:04:06,180 --> 00:04:08,370
various birds but I've taken a much

74
00:04:08,370 --> 00:04:11,100
simple approach for this example if the

75
00:04:11,100 --> 00:04:13,200
ratio of the wings thrust to the weight

76
00:04:13,200 --> 00:04:15,240
of the bird is greater than one we're

77
00:04:15,240 --> 00:04:17,339
going to say that the wing can fly if

78
00:04:17,339 --> 00:04:18,600
it's equal to 1

79
00:04:18,600 --> 00:04:20,329
the bird has to flap hard to get off the

80
00:04:20,329 --> 00:04:22,440
ground and if it's less than 1 then the

81
00:04:22,440 --> 00:04:24,080
wing won't lift the bird

82
00:04:24,080 --> 00:04:26,220
ok now we get to see composition in

83
00:04:26,220 --> 00:04:28,170
action I'm going to go through all the

84
00:04:28,170 --> 00:04:30,090
code once we've seen it working since it

85
00:04:30,090 --> 00:04:31,950
makes more sense once you see what does

86
00:04:31,950 --> 00:04:34,680
so go back to the duck method and need to

87
00:04:34,680 --> 00:04:38,640
add a constructor....

88
00:04:38,640 --> 00:04:41,670
...

89
00:04:41,670 --> 00:04:45,810
....

90
00:04:45,810 --> 00:04:51,990
...

91
00:04:51,990 --> 00:04:53,970
....

92
00:04:53,970 --> 00:04:57,810
...

93
00:04:57,810 --> 00:05:12,060
...

94
00:05:12,060 --> 00:05:15,420
....

95
00:05:15,420 --> 00:05:20,160
...so let's just run this we get the

96
00:05:20,160 --> 00:05:22,170
result we this is fun so and again we

97
00:05:22,170 --> 00:05:24,780
this is fun is coming from self .

98
00:05:24,780 --> 00:05:28,290
ratio being greater than one there so what

99
00:05:28,290 --> 00:05:29,520
if we actually done here

100
00:05:29,520 --> 00:05:32,430
well in the init method for duck class

101
00:05:32,430 --> 00:05:35,790
on line 17 we create a new

102
00:05:35,790 --> 00:05:38,070
wing object and assign it to the _

103
00:05:38,070 --> 00:05:41,400
wing attribute of the duck class now

104
00:05:41,400 --> 00:05:43,620
any duck objects we create will have

105
00:05:43,620 --> 00:05:45,810
their own wing object and can use the

106
00:05:45,810 --> 00:05:48,480
attributes of a wing including this case

107
00:05:48,480 --> 00:05:50,760
the fly method now when a class

108
00:05:50,760 --> 00:05:52,500
contains another object like this

109
00:05:52,500 --> 00:05:55,620
that's called composition now we could

110
00:05:55,620 --> 00:05:57,810
add a leg class and a beak and build a

111
00:05:57,810 --> 00:05:59,880
complete duck out of component parts

112
00:05:59,880 --> 00:06:02,550
the duck would then be composed of

113
00:06:02,550 --> 00:06:05,280
other classes and would have few or no

114
00:06:05,280 --> 00:06:07,470
attributes of its own that weren't provided

115
00:06:07,470 --> 00:06:10,050
by the composing classes now that's

116
00:06:10,050 --> 00:06:11,850
probably a bit extreme for a duck but

117
00:06:11,850 --> 00:06:14,070
could make perfect sense if we were for

118
00:06:14,070 --> 00:06:17,100
example representing an HTML document so

119
00:06:17,100 --> 00:06:19,260
let's actually do that instead seeing

120
00:06:19,260 --> 00:06:21,120
composition being used in a more

121
00:06:21,120 --> 00:06:23,580
realistic situation is a good way to get

122
00:06:23,580 --> 00:06:25,530
a feel for how powerful a technique can

123
00:06:25,530 --> 00:06:27,990
be so let's create a new python file

124
00:06:27,990 --> 00:06:32,550
new python and will call this one

125
00:06:32,550 --> 00:06:40,050
....now I'm not going

126
00:06:40,050 --> 00:06:42,180
to actually explain html here

127
00:06:42,180 --> 00:06:43,890
most people already know the basics of

128
00:06:43,890 --> 00:06:46,410
HTML even if you haven't created any web

129
00:06:46,410 --> 00:06:49,320
pages using it a HTML document is

130
00:06:49,320 --> 00:06:51,450
basically a structured document that

131
00:06:51,450 --> 00:06:54,210
uses tags to enclose text the browser

132
00:06:54,210 --> 00:06:56,070
uses those tags to work on how to display

133
00:06:56,070 --> 00:06:58,410
the text let's just have a quick look at

134
00:06:58,410 --> 00:07:00,120
the structure of HTML document open a

135
00:07:00,120 --> 00:07:04,350
browser and do a search here for HTML

136
00:07:04,350 --> 00:07:10,290
document structure the first results

137
00:07:10,290 --> 00:07:12,240
telling us what it is without us having

138
00:07:12,240 --> 00:07:14,640
to follow the link and probably the

139
00:07:14,640 --> 00:07:16,260
better one here definition is

140
00:07:16,260 --> 00:07:17,610
this one here the global structure of

141
00:07:17,610 --> 00:07:19,950
HTML document i could click on that

142
00:07:19,950 --> 00:07:24,900
and look and these three lines here

143
00:07:24,900 --> 00:07:26,910
probably sum it up pretty well there's

144
00:07:26,910 --> 00:07:28,890
three parts that a HTML document must

145
00:07:28,890 --> 00:07:31,500
have a line containing HTML version

146
00:07:31,500 --> 00:07:33,720
information that's called the document

147
00:07:33,720 --> 00:07:36,960
type definition or DTD a header section and

148
00:07:36,960 --> 00:07:39,540
a document body and we've got an example

149
00:07:39,540 --> 00:07:41,850
on the screen here so at this point what we

150
00:07:41,850 --> 00:07:43,290
can do is we can say that a html

151
00:07:43,290 --> 00:07:46,680
document has a DTD and it has a header

152
00:07:46,680 --> 00:07:49,530
and it has a body when you've got has a

153
00:07:49,530 --> 00:07:51,360
relationships like this that's an

154
00:07:51,360 --> 00:07:52,980
indication that we could consider we

155
00:07:52,980 --> 00:07:55,590
should consider using composition when

156
00:07:55,590 --> 00:07:57,030
creating a class

157
00:07:57,030 --> 00:07:59,820
ok so the basic building block of HTML

158
00:07:59,820 --> 00:08:00,930
is the tag

159
00:08:00,930 --> 00:08:03,690
let's go back to code and start creating

160
00:08:03,690 --> 00:08:04,410
a tag

161
00:08:04,410 --> 00:08:12,660
class.....

162
00:08:12,660 --> 00:08:14,430
....

163
00:08:14,430 --> 00:08:35,539
....

164
00:08:35,539 --> 00:08:40,789
...

165
00:08:40,789 --> 00:08:43,159
....

166
00:08:43,159 --> 00:08:46,530
...

167
00:08:46,530 --> 00:08:58,080
...

168
00:08:58,080 --> 00:09:00,690
....

169
00:09:00,690 --> 00:09:02,040
....

170
00:09:02,040 --> 00:09:06,710
we also want to create the string....

171
00:09:06,710 --> 00:09:08,760
...

172
00:09:08,760 --> 00:09:14,520
....

173
00:09:14,520 --> 00:09:18,150
...

174
00:09:18,150 --> 00:09:21,090
....

175
00:09:21,090 --> 00:09:24,480
....

176
00:09:24,480 --> 00:09:27,660
...

177
00:09:27,660 --> 00:09:37,170
...

178
00:09:37,170 --> 00:09:42,600
....

179
00:09:42,600 --> 00:09:46,170
...

180
00:09:46,170 --> 00:09:47,940
...

181
00:09:47,940 --> 00:09:52,260
ok now if you're not familiar with HTML

182
00:09:52,260 --> 00:09:54,240
tags they have a name which is enclosed

183
00:09:54,240 --> 00:09:56,940
in angle brackets the tag is close by

184
00:09:56,940 --> 00:09:59,010
using a similar tag but with a slash

185
00:09:59,010 --> 00:10:00,420
before the name that's what we're trying

186
00:10:00,420 --> 00:10:02,640
to do the definitions on line 4 and 5

187
00:10:02,640 --> 00:10:05,820
if you go back to our browser again

188
00:10:05,820 --> 00:10:10,380
in the structure here and you can see

189
00:10:10,380 --> 00:10:13,560
the definition their now the DTD looks

190
00:10:13,560 --> 00:10:15,660
quite complicated but it always takes

191
00:10:15,660 --> 00:10:17,810
one of the few forms so when

192
00:10:17,810 --> 00:10:19,250
getting a webpage you just copy and

193
00:10:19,250 --> 00:10:21,400
paste it the rest of the documents in

194
00:10:21,400 --> 00:10:23,090
close as you can see there in HTML

195
00:10:23,090 --> 00:10:25,700
starting tag up here and ends with the

196
00:10:25,700 --> 00:10:28,210
closing HTML tag down here notice how its

197
00:10:28,210 --> 00:10:29,690
got a / in front of it for the closing

198
00:10:29,690 --> 00:10:32,480
one and obviously we can see that on how it

199
00:10:32,480 --> 00:10:35,020
works in the example here now the tag

200
00:10:35,020 --> 00:10:37,130
names aren't case sensitive so i'm going to

201
00:10:37,130 --> 00:10:38,770
be using lower case for no other reason

202
00:10:38,770 --> 00:10:41,360
that I prefer typing it in lowercase now

203
00:10:41,360 --> 00:10:44,020
within the HTML tag their is a head tag as you

204
00:10:44,020 --> 00:10:46,960
can see here followed by body tag down

205
00:10:46,960 --> 00:10:50,390
here the contents of the head tag up

206
00:10:50,390 --> 00:10:52,700
here include a title and the bodies

207
00:10:52,700 --> 00:10:55,760
contents here a single paragraph would

208
00:10:55,760 --> 00:10:58,190
start with that p with the less than

209
00:10:58,190 --> 00:10:59,900
greater than sign so the P tag in other

210
00:10:59,900 --> 00:11:02,330
words strictly speaking looking at this

211
00:11:02,330 --> 00:11:04,850
code there should be a closing P

212
00:11:04,850 --> 00:11:08,020
tags in other words a less than sign / p

213
00:11:08,020 --> 00:11:10,790
greater than sign closing tag but the

214
00:11:10,790 --> 00:11:12,400
HTML specification isn't very

215
00:11:12,400 --> 00:11:14,360
restrictive so you'll often find that

216
00:11:14,360 --> 00:11:17,600
tags aren't closed xml on the other hand is

217
00:11:17,600 --> 00:11:19,940
stricter and all tags there must be

218
00:11:19,940 --> 00:11:22,190
closed so as this example is at the

219
00:11:22,190 --> 00:11:24,020
moment you couldn't use an xml parser to

220
00:11:24,020 --> 00:11:25,790
read this html code it will

221
00:11:25,790 --> 00:11:27,860
actually fail because there's no

222
00:11:27,860 --> 00:11:29,710
closing P tag here

223
00:11:29,710 --> 00:11:31,850
alright so that's the sort of thing our

224
00:11:31,850 --> 00:11:33,650
classes are looking to create or going

225
00:11:33,650 --> 00:11:35,690
to create let's go back to intelliJ

226
00:11:35,690 --> 00:11:38,630
now the tag class constructor

227
00:11:38,630 --> 00:11:40,850
initializes the init method up here

228
00:11:40,850 --> 00:11:43,550
on line three accept a name for the tag

229
00:11:43,550 --> 00:11:46,040
and its contents it then uses string

230
00:11:46,040 --> 00:11:48,620
formatting to create the start and end tags

231
00:11:48,620 --> 00:11:50,810
and stores the contents in the self dot

232
00:11:50,810 --> 00:11:53,870
contents data attribute now the string

233
00:11:53,870 --> 00:11:56,120
method the STR method will return the

234
00:11:56,120 --> 00:11:58,100
complete string for the tag so that's

235
00:11:58,100 --> 00:12:00,230
the opening tag followed by the contents

236
00:12:00,230 --> 00:12:03,020
and finishing with the closing tag and

237
00:12:03,020 --> 00:12:04,580
as i mentioned i'm also giving the

238
00:12:04,580 --> 00:12:06,680
class a display method just prints the

239
00:12:06,680 --> 00:12:09,140
instance out as we saw earlier the print

240
00:12:09,140 --> 00:12:10,670
function we use the result of the string

241
00:12:10,670 --> 00:12:11,690
method to do that

242
00:12:11,690 --> 00:12:14,200
alright so next we need a doc type class

243
00:12:14,200 --> 00:12:17,480
so let's go ahead and create that it's

244
00:12:17,480 --> 00:12:21,830
gonna be class....

245
00:12:21,830 --> 00:12:24,110
....

246
00:12:24,110 --> 00:12:27,290
...

247
00:12:27,290 --> 00:12:40,130
...

248
00:12:40,130 --> 00:12:42,260
....

249
00:12:42,260 --> 00:12:46,310
...

250
00:12:46,310 --> 00:13:20,600
...

251
00:13:20,600 --> 00:13:27,590
alright so doc type inherits from tagged and

252
00:13:27,590 --> 00:13:29,330
uses the super method to initialize

253
00:13:29,330 --> 00:13:31,850
itself with the DTD that we saw on the

254
00:13:31,850 --> 00:13:34,310
webpage now doctype doesn't have any

255
00:13:34,310 --> 00:13:36,800
contents and there's also no closing tag

256
00:13:36,800 --> 00:13:38,960
so we are setting that the closing tag

257
00:13:38,960 --> 00:13:41,360
the end tag on line 19 to an empty string

258
00:13:41,360 --> 00:13:44,030
but hang on though I've just extended

259
00:13:44,030 --> 00:13:45,860
the tag class doesn't that mean we're

260
00:13:45,860 --> 00:13:47,420
using inheritance here rather than

261
00:13:47,420 --> 00:13:48,470
composition

262
00:13:48,470 --> 00:13:51,230
yes we are now the two approaches are

263
00:13:51,230 --> 00:13:53,810
exclusive and you can create a class

264
00:13:53,810 --> 00:13:56,930
hierarchy using inheritance and then use

265
00:13:56,930 --> 00:13:58,460
those classes in a composition

266
00:13:58,460 --> 00:14:00,710
relationship to build up another class

267
00:14:00,710 --> 00:14:04,160
when using composition you have to have

268
00:14:04,160 --> 00:14:06,500
some classes to compose a class out of

269
00:14:06,500 --> 00:14:08,950
so our HTML document class will be

270
00:14:08,950 --> 00:14:12,160
composed of a DTD the header and a body

271
00:14:12,160 --> 00:14:14,260
at the moment we're creating those

272
00:14:14,260 --> 00:14:15,250
classes

273
00:14:15,250 --> 00:14:17,080
we're going to come to composition when

274
00:14:17,080 --> 00:14:20,050
we create the HTML . class in a minute

275
00:14:20,050 --> 00:14:22,240
for now though let's just finish off

276
00:14:22,240 --> 00:14:25,000
this video by creating the head and body

277
00:14:25,000 --> 00:14:27,940
classes and turns out the head is going

278
00:14:27,940 --> 00:14:30,310
to be very simple class to create we're

279
00:14:30,310 --> 00:14:33,370
going to go ahead and do that it'll be....

280
00:14:33,370 --> 00:14:35,410
....

281
00:14:35,410 --> 00:14:37,390
....

282
00:14:37,390 --> 00:14:44,740
...

283
00:14:44,740 --> 00:14:53,890
...

284
00:14:53,890 --> 00:14:55,060
....

285
00:14:55,060 --> 00:14:58,090
....so just going to be there

286
00:14:58,090 --> 00:14:59,920
the head opening and closing tags with
....so just going to be there

287
00:14:59,920 --> 00:15:01,480
no content that's what we've actually

288
00:15:01,480 --> 00:15:04,660
done there in the head class if we want

289
00:15:04,660 --> 00:15:06,520
this to be complete we should actually

290
00:15:06,520 --> 00:15:08,260
add similar code to what I'm going to

291
00:15:08,260 --> 00:15:10,510
write in the body class but I don't want

292
00:15:10,510 --> 00:15:11,800
to get distracted by those sorts of

293
00:15:11,800 --> 00:15:14,560
things that go into the header so to

294
00:15:14,560 --> 00:15:16,030
keep things simple our header is going to be

295
00:15:16,030 --> 00:15:18,400
empty for now although I can sense the

296
00:15:18,400 --> 00:15:19,780
a challenge is coming up

297
00:15:19,780 --> 00:15:22,510
ok let's finish off now and create

298
00:15:22,510 --> 00:15:24,940
the body class and end

299
00:15:24,940 --> 00:15:26,230
the video move on to the next

300
00:15:26,230 --> 00:15:35,560
one so class body tag....

301
00:15:35,560 --> 00:15:40,480
....

302
00:15:40,480 --> 00:15:43,840
....

303
00:15:43,840 --> 00:15:46,630
...

304
00:15:46,630 --> 00:15:48,490
....

305
00:15:48,490 --> 00:15:52,360
...

306
00:15:52,360 --> 00:15:55,330
...

307
00:15:55,330 --> 00:15:56,500
....

308
00:15:56,500 --> 00:16:08,740
....

309
00:16:08,740 --> 00:16:11,470
alright so let's add method to add the

310
00:16:11,470 --> 00:16:14,260
tag we're going to put....

311
00:16:14,260 --> 00:16:21,370
....

312
00:16:21,370 --> 00:16:25,960
...

313
00:16:25,960 --> 00:16:35,830
...

314
00:16:35,830 --> 00:16:37,090
....

315
00:16:37,090 --> 00:16:41,290
....

316
00:16:41,290 --> 00:16:44,860
...

317
00:16:44,860 --> 00:16:47,890
....

318
00:16:47,890 --> 00:16:52,270
...

319
00:16:52,270 --> 00:17:08,950
...

320
00:17:08,950 --> 00:17:12,010
alright let's just discuss this briefly

321
00:17:12,010 --> 00:17:15,329
before we end the video so once again for

322
00:17:15,329 --> 00:17:17,020
the body class were inheriting from the

323
00:17:17,020 --> 00:17:19,200
tag class but we initialize the

324
00:17:19,200 --> 00:17:21,250
contents to an empty string when calling

325
00:17:21,250 --> 00:17:23,230
the super method because we don't what

326
00:17:23,230 --> 00:17:26,740
the contents to be created just yet and

327
00:17:26,740 --> 00:17:27,880
that's because we're going to store all

328
00:17:27,880 --> 00:17:29,410
the contents and list as you can probably

329
00:17:29,410 --> 00:17:31,870
ascertain in the attribute self dot

330
00:17:31,870 --> 00:17:34,360
_body_ contents so we

331
00:17:34,360 --> 00:17:35,980
initialize that to an empty list in the

332
00:17:35,980 --> 00:17:38,230
constructor can see them doing that on line

333
00:17:38,230 --> 00:17:41,110
32 now the add _ tag methods

334
00:17:41,110 --> 00:17:43,930
used to add the content to our body and

335
00:17:43,930 --> 00:17:45,460
we give it a name of a tag and the

336
00:17:45,460 --> 00:17:47,590
contents and it creates a new tag

337
00:17:47,590 --> 00:17:49,600
instance and appends that to the body

338
00:17:49,600 --> 00:17:52,240
contents list i'm going to move swiftly

339
00:17:52,240 --> 00:17:54,130
on here but you may already spotted this

340
00:17:54,130 --> 00:17:56,800
is an example of composition absolutely

341
00:17:56,800 --> 00:17:58,030
it is and I will come back and talk

342
00:17:58,030 --> 00:18:00,580
about that more in the next video i want

343
00:18:00,580 --> 00:18:02,530
to show you the use of composition in

344
00:18:02,530 --> 00:18:04,690
the document first because that's a much

345
00:18:04,690 --> 00:18:07,270
clearer example so moving on in the

346
00:18:07,270 --> 00:18:08,950
display method as you can see there on

347
00:18:08,950 --> 00:18:11,830
line 38 overrides the method from the

348
00:18:11,830 --> 00:18:14,320
tag superclass so it builds up the

349
00:18:14,320 --> 00:18:16,750
contents attribute by iterating over our

350
00:18:16,750 --> 00:18:19,030
body contents list and adding each tag

351
00:18:19,030 --> 00:18:21,490
to the contents and once thats done it

352
00:18:21,490 --> 00:18:23,590
then uses the superclass display method

353
00:18:23,590 --> 00:18:25,660
to display the body tag with the full

354
00:18:25,660 --> 00:18:26,590
contents

355
00:18:26,590 --> 00:18:28,510
now if you were going to fully implement

356
00:18:28,510 --> 00:18:30,760
the header then we could give our head

357
00:18:30,760 --> 00:18:33,220
class the same ability to add tags and

358
00:18:33,220 --> 00:18:35,350
build up its contents in fact we might

359
00:18:35,350 --> 00:18:37,930
create a special kind of tag class that

360
00:18:37,930 --> 00:18:40,000
can contain other tags and have both

361
00:18:40,000 --> 00:18:42,340
head and body inherit from that but we

362
00:18:42,340 --> 00:18:44,050
are trying to keep things simple here

363
00:18:44,050 --> 00:18:45,790
alright so I'm going to finish the video

364
00:18:45,790 --> 00:18:48,100
here now in the next video

365
00:18:48,100 --> 00:18:49,390
now that we've got all the classes that

366
00:18:49,390 --> 00:18:52,330
we need to make up our HTML document we

367
00:18:52,330 --> 00:18:54,700
can create the actual document class so

368
00:18:54,700 --> 00:19:01,500
let's work on that in the next video

