WEBVTT 1 00:00:01.700 --> 00:00:03.770 in the previous video we have a look at 2 00:00:03.770 --> 00:00:06.140 polymorphism and we saw how different in the previous video we have a look at 3 00:00:06.140 --> 00:00:08.210 objects can inherit similar behavior polymorphism and we saw how different 4 00:00:08.210 --> 00:00:11.780 from a common base class so although ints objects can inherit similar behavior 5 00:00:11.780 --> 00:00:13.790 floats and lists are different types from a common base class so although ints 6 00:00:13.790 --> 00:00:15.679 they can all be printed floats and lists are different types 7 00:00:15.679 --> 00:00:16.760 that's because they will provide a they can all be printed 8 00:00:16.760 --> 00:00:19.610 string or STR method if a type doesn't that's because they will provide a 9 00:00:19.610 --> 00:00:21.890 provide a specific implementation of str string or STR method if a type doesn't 10 00:00:21.890 --> 00:00:24.380 string method it ends up provide a specific implementation of str 11 00:00:24.380 --> 00:00:25.940 getting inherited from the base object string method it ends up 12 00:00:25.940 --> 00:00:28.820 class so python isn't really interested getting inherited from the base object 13 00:00:28.820 --> 00:00:31.010 in what type something it focus class so python isn't really interested 14 00:00:31.010 --> 00:00:33.770 instead on how things behave so again if in what type something it focus 15 00:00:33.770 --> 00:00:36.530 it quacks like a duck it's a duck when instead on how things behave so again if 16 00:00:36.530 --> 00:00:38.120 we finish the last video by giving our it quacks like a duck it's a duck when 17 00:00:38.120 --> 00:00:40.370 penguin class the same methods as the we finish the last video by giving our 18 00:00:40.370 --> 00:00:43.310 duck class so that penguin would behave penguin class the same methods as the 19 00:00:43.310 --> 00:00:46.340 the same as a duck so inheritance isn't duck class so that penguin would behave 20 00:00:46.340 --> 00:00:48.980 the only way to implement polymorphism a the same as a duck so inheritance isn't 21 00:00:48.980 --> 00:00:50.600 class can behave in the same way as the only way to implement polymorphism a 22 00:00:50.600 --> 00:00:52.579 another class as long as it's got the class can behave in the same way as 23 00:00:52.579 --> 00:00:55.730 necessary methods and data attributes so another class as long as it's got the 24 00:00:55.730 --> 00:00:57.620 relating this back to our enemy objects necessary methods and data attributes so 25 00:00:57.620 --> 00:01:00.710 we can say that a troll is an enemy and a relating this back to our enemy objects 26 00:01:00.710 --> 00:01:03.410 vampire is an enemy so inheritance we can say that a troll is an enemy and a 27 00:01:03.410 --> 00:01:06.079 results in a is a relationship and vampire is an enemy so inheritance 28 00:01:06.079 --> 00:01:09.439 similarly a penguin is a duck at least results in a is a relationship and 29 00:01:09.439 --> 00:01:11.030 as far as that test_duck similarly a penguin is a duck at least 30 00:01:11.030 --> 00:01:13.369 functions concerned so in this video as far as that test_duck 31 00:01:13.369 --> 00:01:15.170 we're going to start having a look at functions concerned so in this video 32 00:01:15.170 --> 00:01:17.119 two other object orientated terms we're going to start having a look at 33 00:01:17.119 --> 00:01:20.659 composition and aggregation now two other object orientated terms 34 00:01:20.659 --> 00:01:23.030 composition and aggregation are used when composition and aggregation now 35 00:01:23.030 --> 00:01:25.159 you have a has a relationship rather composition and aggregation are used when 36 00:01:25.159 --> 00:01:27.920 than a is a relationship so if we go you have a has a relationship rather 37 00:01:27.920 --> 00:01:30.049 have a bird's wings we wouldn't say that than a is a relationship so if we go 38 00:01:30.049 --> 00:01:32.689 a duck is a wing would say that duck has have a bird's wings we wouldn't say that 39 00:01:32.689 --> 00:01:34.639 a wing now if you're unsure about a duck is a wing would say that duck has 40 00:01:34.639 --> 00:01:36.139 whether you should use inheritance or a wing now if you're unsure about 41 00:01:36.139 --> 00:01:38.329 not then those two ways of looking at whether you should use inheritance or 42 00:01:38.329 --> 00:01:40.459 the relationship will normally make it not then those two ways of looking at 43 00:01:40.459 --> 00:01:42.079 obvious whether inheritance is the relationship will normally make it 44 00:01:42.079 --> 00:01:44.719 appropriate or not what I'm going to do is obvious whether inheritance is 45 00:01:44.719 --> 00:01:47.209 going back over here now to our duck appropriate or not what I'm going to do is 46 00:01:47.209 --> 00:01:50.659 .py again I'm just going to comment going back over here now to our duck 47 00:01:50.659 --> 00:01:53.119 at this code at the bottom for new so .py again I'm just going to comment 48 00:01:53.119 --> 00:01:54.259 what I'll do is I'll comment the at this code at the bottom for new so 49 00:01:54.259 --> 00:01:57.740 test duck altogether and we'll just what I'll do is I'll comment the 50 00:01:57.740 --> 00:01:58.999 like Donald in will just comment out test duck altogether and we'll just 51 00:01:58.999 --> 00:02:02.990 percy for now and I'll just delete the call like Donald in will just comment out 52 00:02:02.990 --> 00:02:04.700 to test _ ducks so we are just left percy for now and I'll just delete the call 53 00:02:04.700 --> 00:02:08.479 now with defining donal alright so to test _ ducks so we are just left 54 00:02:08.479 --> 00:02:10.340 let's add a wing class to the start of a now with defining donal alright so 55 00:02:10.340 --> 00:02:12.260 main file and we are going to give duck let's add a wing class to the start of a 56 00:02:12.260 --> 00:02:14.480 class wings so at the top main file and we are going to give duck 57 00:02:14.480 --> 00:02:23.750 here..... class wings so at the top 58 00:02:23.750 --> 00:02:26.180 ... here..... 59 00:02:26.180 --> 00:02:29.209 ... ... 60 00:02:29.209 --> 00:02:31.190 .... ... 61 00:02:31.190 --> 00:02:35.000 ... .... 62 00:02:35.000 --> 00:03:39.140 ... ... 63 00:03:39.140 --> 00:03:41.330 ok the couple of extra lines to keep intellij ... 64 00:03:41.330 --> 00:03:44.870 happy now this is simplified ok the couple of extra lines to keep intellij 65 00:03:44.870 --> 00:03:47.540 slightly so whether wing is capable of happy now this is simplified 66 00:03:47.540 --> 00:03:50.330 lifting an object such as a duck depends slightly so whether wing is capable of 67 00:03:50.330 --> 00:03:51.530 on things like the weight of the object lifting an object such as a duck depends 68 00:03:51.530 --> 00:03:54.020 the surface area and shape of the wing on things like the weight of the object 69 00:03:54.020 --> 00:03:56.870 and its speed through the air and we the surface area and shape of the wing 70 00:03:56.870 --> 00:03:58.730 could apply Newton's law and put in the and its speed through the air and we 71 00:03:58.730 --> 00:04:01.310 correct formula to decide if our wings could apply Newton's law and put in the 72 00:04:01.310 --> 00:04:03.050 capable of flying when it's attached to correct formula to decide if our wings 73 00:04:03.050 --> 00:04:05.240 various birds but I've taken a much capable of flying when it's attached to 74 00:04:05.240 --> 00:04:07.970 simple approach for this example if the various birds but I've taken a much 75 00:04:07.970 --> 00:04:10.070 ratio of the wings thrust to the weight simple approach for this example if the 76 00:04:10.070 --> 00:04:12.110 of the bird is greater than one we're ratio of the wings thrust to the weight 77 00:04:12.110 --> 00:04:14.210 going to say that the wing can fly if of the bird is greater than one we're 78 00:04:14.210 --> 00:04:15.470 it's equal to 1 going to say that the wing can fly if 79 00:04:15.470 --> 00:04:17.209 the bird has to flap hard to get off the it's equal to 1 80 00:04:17.209 --> 00:04:19.310 ground and if it's less than 1 then the the bird has to flap hard to get off the 81 00:04:19.310 --> 00:04:20.959 wing won't lift the bird ground and if it's less than 1 then the 82 00:04:20.959 --> 00:04:23.090 ok now we get to see composition in wing won't lift the bird 83 00:04:23.090 --> 00:04:25.040 action I'm going to go through all the ok now we get to see composition in 84 00:04:25.040 --> 00:04:26.960 code once we've seen it working since it action I'm going to go through all the 85 00:04:26.960 --> 00:04:28.820 makes more sense once you see what does code once we've seen it working since it 86 00:04:28.820 --> 00:04:31.550 so go back to the duck method and need to makes more sense once you see what does 87 00:04:31.550 --> 00:04:35.510 add a constructor.... so go back to the duck method and need to 88 00:04:35.510 --> 00:04:38.540 ... add a constructor.... 89 00:04:38.540 --> 00:04:42.680 .... ... 90 00:04:42.680 --> 00:04:48.860 ... .... 91 00:04:48.860 --> 00:04:50.840 .... ... 92 00:04:50.840 --> 00:04:54.680 ... .... 93 00:04:54.680 --> 00:05:08.930 ... ... 94 00:05:08.930 --> 00:05:12.290 .... ... 95 00:05:12.290 --> 00:05:17.030 ...so let's just run this we get the .... 96 00:05:17.030 --> 00:05:19.040 result we this is fun so and again we ...so let's just run this we get the 97 00:05:19.040 --> 00:05:21.650 this is fun is coming from self . result we this is fun so and again we 98 00:05:21.650 --> 00:05:25.160 ratio being greater than one there so what this is fun is coming from self . 99 00:05:25.160 --> 00:05:26.390 if we actually done here ratio being greater than one there so what 100 00:05:26.390 --> 00:05:29.300 well in the init method for duck class if we actually done here 101 00:05:29.300 --> 00:05:32.660 on line 17 we create a new well in the init method for duck class 102 00:05:32.660 --> 00:05:34.940 wing object and assign it to the _ on line 17 we create a new 103 00:05:34.940 --> 00:05:38.270 wing attribute of the duck class now wing object and assign it to the _ 104 00:05:38.270 --> 00:05:40.490 any duck objects we create will have wing attribute of the duck class now 105 00:05:40.490 --> 00:05:42.680 their own wing object and can use the any duck objects we create will have 106 00:05:42.680 --> 00:05:45.350 attributes of a wing including this case their own wing object and can use the 107 00:05:45.350 --> 00:05:47.630 the fly method now when a class attributes of a wing including this case 108 00:05:47.630 --> 00:05:49.370 contains another object like this the fly method now when a class 109 00:05:49.370 --> 00:05:52.490 that's called composition now we could contains another object like this 110 00:05:52.490 --> 00:05:54.680 add a leg class and a beak and build a that's called composition now we could 111 00:05:54.680 --> 00:05:56.750 complete duck out of component parts add a leg class and a beak and build a 112 00:05:56.750 --> 00:05:59.420 the duck would then be composed of complete duck out of component parts 113 00:05:59.420 --> 00:06:02.150 other classes and would have few or no the duck would then be composed of 114 00:06:02.150 --> 00:06:04.340 attributes of its own that weren't provided other classes and would have few or no 115 00:06:04.340 --> 00:06:06.920 by the composing classes now that's attributes of its own that weren't provided 116 00:06:06.920 --> 00:06:08.720 probably a bit extreme for a duck but by the composing classes now that's 117 00:06:08.720 --> 00:06:10.940 could make perfect sense if we were for probably a bit extreme for a duck but 118 00:06:10.940 --> 00:06:13.970 example representing an HTML document so could make perfect sense if we were for 119 00:06:13.970 --> 00:06:16.130 let's actually do that instead seeing example representing an HTML document so 120 00:06:16.130 --> 00:06:17.990 composition being used in a more let's actually do that instead seeing 121 00:06:17.990 --> 00:06:20.450 realistic situation is a good way to get composition being used in a more 122 00:06:20.450 --> 00:06:22.400 a feel for how powerful a technique can realistic situation is a good way to get 123 00:06:22.400 --> 00:06:24.860 be so let's create a new python file a feel for how powerful a technique can 124 00:06:24.860 --> 00:06:29.420 new python and will call this one be so let's create a new python file 125 00:06:29.420 --> 00:06:36.920 ....now I'm not going new python and will call this one 126 00:06:36.920 --> 00:06:39.050 to actually explain html here ....now I'm not going 127 00:06:39.050 --> 00:06:40.760 most people already know the basics of to actually explain html here 128 00:06:40.760 --> 00:06:43.280 HTML even if you haven't created any web most people already know the basics of 129 00:06:43.280 --> 00:06:46.190 pages using it a HTML document is HTML even if you haven't created any web 130 00:06:46.190 --> 00:06:48.320 basically a structured document that pages using it a HTML document is 131 00:06:48.320 --> 00:06:51.080 uses tags to enclose text the browser basically a structured document that 132 00:06:51.080 --> 00:06:52.940 uses those tags to work on how to display uses tags to enclose text the browser 133 00:06:52.940 --> 00:06:55.280 the text let's just have a quick look at uses those tags to work on how to display 134 00:06:55.280 --> 00:06:56.990 the structure of HTML document open a the text let's just have a quick look at 135 00:06:56.990 --> 00:07:01.220 browser and do a search here for HTML the structure of HTML document open a 136 00:07:01.220 --> 00:07:07.160 document structure the first results browser and do a search here for HTML 137 00:07:07.160 --> 00:07:09.110 telling us what it is without us having document structure the first results 138 00:07:09.110 --> 00:07:11.510 to follow the link and probably the telling us what it is without us having 139 00:07:11.510 --> 00:07:13.130 better one here definition is to follow the link and probably the 140 00:07:13.130 --> 00:07:14.480 this one here the global structure of better one here definition is 141 00:07:14.480 --> 00:07:16.820 HTML document i could click on that this one here the global structure of 142 00:07:16.820 --> 00:07:21.770 and look and these three lines here HTML document i could click on that 143 00:07:21.770 --> 00:07:23.780 probably sum it up pretty well there's and look and these three lines here 144 00:07:23.780 --> 00:07:25.760 three parts that a HTML document must probably sum it up pretty well there's 145 00:07:25.760 --> 00:07:28.370 have a line containing HTML version three parts that a HTML document must 146 00:07:28.370 --> 00:07:30.590 information that's called the document have a line containing HTML version 147 00:07:30.590 --> 00:07:33.830 type definition or DTD a header section and information that's called the document 148 00:07:33.830 --> 00:07:36.410 a document body and we've got an example type definition or DTD a header section and 149 00:07:36.410 --> 00:07:38.720 on the screen here so at this point what we a document body and we've got an example 150 00:07:38.720 --> 00:07:40.160 can do is we can say that a html on the screen here so at this point what we 151 00:07:40.160 --> 00:07:43.550 document has a DTD and it has a header can do is we can say that a html 152 00:07:43.550 --> 00:07:46.400 and it has a body when you've got has a document has a DTD and it has a header 153 00:07:46.400 --> 00:07:48.230 relationships like this that's an and it has a body when you've got has a 154 00:07:48.230 --> 00:07:49.850 indication that we could consider we relationships like this that's an 155 00:07:49.850 --> 00:07:52.460 should consider using composition when indication that we could consider we 156 00:07:52.460 --> 00:07:53.900 creating a class should consider using composition when 157 00:07:53.900 --> 00:07:56.690 ok so the basic building block of HTML creating a class 158 00:07:56.690 --> 00:07:57.800 is the tag ok so the basic building block of HTML 159 00:07:57.800 --> 00:08:00.560 let's go back to code and start creating is the tag 160 00:08:00.560 --> 00:08:01.280 a tag let's go back to code and start creating 161 00:08:01.280 --> 00:08:09.530 class..... a tag 162 00:08:09.530 --> 00:08:11.300 .... class..... 163 00:08:11.300 --> 00:08:32.419 .... .... 164 00:08:32.419 --> 00:08:37.669 ... .... 165 00:08:37.669 --> 00:08:40.039 .... ... 166 00:08:40.039 --> 00:08:43.400 ... .... 167 00:08:43.400 --> 00:08:54.950 ... ... 168 00:08:54.950 --> 00:08:57.560 .... ... 169 00:08:57.560 --> 00:08:58.910 .... .... 170 00:08:58.910 --> 00:09:03.589 we also want to create the string.... .... 171 00:09:03.589 --> 00:09:05.630 ... we also want to create the string.... 172 00:09:05.630 --> 00:09:11.390 .... ... 173 00:09:11.390 --> 00:09:15.020 ... .... 174 00:09:15.020 --> 00:09:17.960 .... ... 175 00:09:17.960 --> 00:09:21.350 .... .... 176 00:09:21.350 --> 00:09:24.530 ... .... 177 00:09:24.530 --> 00:09:34.040 ... ... 178 00:09:34.040 --> 00:09:39.470 .... ... 179 00:09:39.470 --> 00:09:43.040 ... .... 180 00:09:43.040 --> 00:09:44.810 ... ... 181 00:09:44.810 --> 00:09:49.130 ok now if you're not familiar with HTML ... 182 00:09:49.130 --> 00:09:51.110 tags they have a name which is enclosed ok now if you're not familiar with HTML 183 00:09:51.110 --> 00:09:53.810 in angle brackets the tag is close by tags they have a name which is enclosed 184 00:09:53.810 --> 00:09:55.880 using a similar tag but with a slash in angle brackets the tag is close by 185 00:09:55.880 --> 00:09:57.290 before the name that's what we're trying using a similar tag but with a slash 186 00:09:57.290 --> 00:09:59.510 to do the definitions on line 4 and 5 before the name that's what we're trying 187 00:09:59.510 --> 00:10:02.690 if you go back to our browser again to do the definitions on line 4 and 5 188 00:10:02.690 --> 00:10:07.250 in the structure here and you can see if you go back to our browser again 189 00:10:07.250 --> 00:10:10.430 the definition their now the DTD looks in the structure here and you can see 190 00:10:10.430 --> 00:10:12.530 quite complicated but it always takes the definition their now the DTD looks 191 00:10:12.530 --> 00:10:14.680 one of the few forms so when quite complicated but it always takes 192 00:10:14.680 --> 00:10:16.120 getting a webpage you just copy and one of the few forms so when 193 00:10:16.120 --> 00:10:18.279 paste it the rest of the documents in getting a webpage you just copy and 194 00:10:18.279 --> 00:10:19.960 close as you can see there in HTML paste it the rest of the documents in 195 00:10:19.960 --> 00:10:22.570 starting tag up here and ends with the close as you can see there in HTML 196 00:10:22.570 --> 00:10:25.089 closing HTML tag down here notice how its starting tag up here and ends with the 197 00:10:25.089 --> 00:10:26.560 got a / in front of it for the closing closing HTML tag down here notice how its 198 00:10:26.560 --> 00:10:29.350 one and obviously we can see that on how it got a / in front of it for the closing 199 00:10:29.350 --> 00:10:31.899 works in the example here now the tag one and obviously we can see that on how it 200 00:10:31.899 --> 00:10:34.000 names aren't case sensitive so i'm going to works in the example here now the tag 201 00:10:34.000 --> 00:10:35.649 be using lower case for no other reason names aren't case sensitive so i'm going to 202 00:10:35.649 --> 00:10:38.230 that I prefer typing it in lowercase now be using lower case for no other reason 203 00:10:38.230 --> 00:10:40.899 within the HTML tag their is a head tag as you that I prefer typing it in lowercase now 204 00:10:40.899 --> 00:10:43.839 can see here followed by body tag down within the HTML tag their is a head tag as you 205 00:10:43.839 --> 00:10:47.260 here the contents of the head tag up can see here followed by body tag down 206 00:10:47.260 --> 00:10:49.570 here include a title and the bodies here the contents of the head tag up 207 00:10:49.570 --> 00:10:52.630 contents here a single paragraph would here include a title and the bodies 208 00:10:52.630 --> 00:10:55.060 start with that p with the less than contents here a single paragraph would 209 00:10:55.060 --> 00:10:56.770 greater than sign so the P tag in other start with that p with the less than 210 00:10:56.770 --> 00:10:59.200 words strictly speaking looking at this greater than sign so the P tag in other 211 00:10:59.200 --> 00:11:01.720 code there should be a closing P words strictly speaking looking at this 212 00:11:01.720 --> 00:11:04.899 tags in other words a less than sign / p code there should be a closing P 213 00:11:04.899 --> 00:11:07.660 greater than sign closing tag but the tags in other words a less than sign / p 214 00:11:07.660 --> 00:11:09.279 HTML specification isn't very greater than sign closing tag but the 215 00:11:09.279 --> 00:11:11.230 restrictive so you'll often find that HTML specification isn't very 216 00:11:11.230 --> 00:11:14.470 tags aren't closed xml on the other hand is restrictive so you'll often find that 217 00:11:14.470 --> 00:11:16.810 stricter and all tags there must be tags aren't closed xml on the other hand is 218 00:11:16.810 --> 00:11:19.060 closed so as this example is at the stricter and all tags there must be 219 00:11:19.060 --> 00:11:20.890 moment you couldn't use an xml parser to closed so as this example is at the 220 00:11:20.890 --> 00:11:22.660 read this html code it will moment you couldn't use an xml parser to 221 00:11:22.660 --> 00:11:24.730 actually fail because there's no read this html code it will 222 00:11:24.730 --> 00:11:26.589 closing P tag here actually fail because there's no 223 00:11:26.589 --> 00:11:28.720 alright so that's the sort of thing our closing P tag here 224 00:11:28.720 --> 00:11:30.520 classes are looking to create or going alright so that's the sort of thing our 225 00:11:30.520 --> 00:11:32.560 to create let's go back to intelliJ classes are looking to create or going 226 00:11:32.560 --> 00:11:35.500 now the tag class constructor to create let's go back to intelliJ 227 00:11:35.500 --> 00:11:37.720 initializes the init method up here now the tag class constructor 228 00:11:37.720 --> 00:11:40.420 on line three accept a name for the tag initializes the init method up here 229 00:11:40.420 --> 00:11:42.910 and its contents it then uses string on line three accept a name for the tag 230 00:11:42.910 --> 00:11:45.490 formatting to create the start and end tags and its contents it then uses string 231 00:11:45.490 --> 00:11:47.680 and stores the contents in the self dot formatting to create the start and end tags 232 00:11:47.680 --> 00:11:50.740 contents data attribute now the string and stores the contents in the self dot 233 00:11:50.740 --> 00:11:52.990 method the STR method will return the contents data attribute now the string 234 00:11:52.990 --> 00:11:54.970 complete string for the tag so that's method the STR method will return the 235 00:11:54.970 --> 00:11:57.100 the opening tag followed by the contents complete string for the tag so that's 236 00:11:57.100 --> 00:11:59.890 and finishing with the closing tag and the opening tag followed by the contents 237 00:11:59.890 --> 00:12:01.450 as i mentioned i'm also giving the and finishing with the closing tag and 238 00:12:01.450 --> 00:12:03.550 class a display method just prints the as i mentioned i'm also giving the 239 00:12:03.550 --> 00:12:06.010 instance out as we saw earlier the print class a display method just prints the 240 00:12:06.010 --> 00:12:07.540 function we use the result of the string instance out as we saw earlier the print 241 00:12:07.540 --> 00:12:08.560 method to do that function we use the result of the string 242 00:12:08.560 --> 00:12:11.079 alright so next we need a doc type class method to do that 243 00:12:11.079 --> 00:12:14.350 so let's go ahead and create that it's alright so next we need a doc type class 244 00:12:14.350 --> 00:12:18.700 gonna be class.... so let's go ahead and create that it's 245 00:12:18.700 --> 00:12:20.980 .... gonna be class.... 246 00:12:20.980 --> 00:12:24.160 ... .... 247 00:12:24.160 --> 00:12:37.000 ... ... 248 00:12:37.000 --> 00:12:39.130 .... ... 249 00:12:39.130 --> 00:12:43.180 ... .... 250 00:12:43.180 --> 00:13:17.470 ... ... 251 00:13:17.470 --> 00:13:24.460 alright so doc type inherits from tagged and ... 252 00:13:24.460 --> 00:13:26.200 uses the super method to initialize alright so doc type inherits from tagged and 253 00:13:26.200 --> 00:13:28.720 itself with the DTD that we saw on the uses the super method to initialize 254 00:13:28.720 --> 00:13:31.180 webpage now doctype doesn't have any itself with the DTD that we saw on the 255 00:13:31.180 --> 00:13:33.670 contents and there's also no closing tag webpage now doctype doesn't have any 256 00:13:33.670 --> 00:13:35.830 so we are setting that the closing tag contents and there's also no closing tag 257 00:13:35.830 --> 00:13:38.230 the end tag on line 19 to an empty string so we are setting that the closing tag 258 00:13:38.230 --> 00:13:40.900 but hang on though I've just extended the end tag on line 19 to an empty string 259 00:13:40.900 --> 00:13:42.730 the tag class doesn't that mean we're but hang on though I've just extended 260 00:13:42.730 --> 00:13:44.290 using inheritance here rather than the tag class doesn't that mean we're 261 00:13:44.290 --> 00:13:45.340 composition using inheritance here rather than 262 00:13:45.340 --> 00:13:48.100 yes we are now the two approaches are composition 263 00:13:48.100 --> 00:13:50.680 exclusive and you can create a class yes we are now the two approaches are 264 00:13:50.680 --> 00:13:53.800 hierarchy using inheritance and then use exclusive and you can create a class 265 00:13:53.800 --> 00:13:55.330 those classes in a composition hierarchy using inheritance and then use 266 00:13:55.330 --> 00:13:57.580 relationship to build up another class those classes in a composition 267 00:13:57.580 --> 00:14:01.030 when using composition you have to have relationship to build up another class 268 00:14:01.030 --> 00:14:03.370 some classes to compose a class out of when using composition you have to have 269 00:14:03.370 --> 00:14:05.820 so our HTML document class will be some classes to compose a class out of 270 00:14:05.820 --> 00:14:09.030 composed of a DTD the header and a body so our HTML document class will be 271 00:14:09.030 --> 00:14:11.130 at the moment we're creating those composed of a DTD the header and a body 272 00:14:11.130 --> 00:14:12.120 classes at the moment we're creating those 273 00:14:12.120 --> 00:14:13.950 we're going to come to composition when classes 274 00:14:13.950 --> 00:14:16.920 we create the HTML . class in a minute we're going to come to composition when 275 00:14:16.920 --> 00:14:19.110 for now though let's just finish off we create the HTML . class in a minute 276 00:14:19.110 --> 00:14:21.870 this video by creating the head and body for now though let's just finish off 277 00:14:21.870 --> 00:14:24.810 classes and turns out the head is going this video by creating the head and body 278 00:14:24.810 --> 00:14:27.180 to be very simple class to create we're classes and turns out the head is going 279 00:14:27.180 --> 00:14:30.240 going to go ahead and do that it'll be.... to be very simple class to create we're 280 00:14:30.240 --> 00:14:32.280 .... going to go ahead and do that it'll be.... 281 00:14:32.280 --> 00:14:34.260 .... .... 282 00:14:34.260 --> 00:14:41.610 ... .... 283 00:14:41.610 --> 00:14:50.760 ... ... 284 00:14:50.760 --> 00:14:51.930 .... ... 285 00:14:51.930 --> 00:14:54.960 ....so just going to be there .... 286 00:14:54.960 --> 00:14:56.790 the head opening and closing tags with ....so just going to be there 287 00:14:56.790 --> 00:14:58.350 no content that's what we've actually the head opening and closing tags with 288 00:14:58.350 --> 00:15:01.530 done there in the head class if we want no content that's what we've actually 289 00:15:01.530 --> 00:15:03.390 this to be complete we should actually done there in the head class if we want 290 00:15:03.390 --> 00:15:05.130 add similar code to what I'm going to this to be complete we should actually 291 00:15:05.130 --> 00:15:07.380 write in the body class but I don't want add similar code to what I'm going to 292 00:15:07.380 --> 00:15:08.670 to get distracted by those sorts of write in the body class but I don't want 293 00:15:08.670 --> 00:15:11.430 things that go into the header so to to get distracted by those sorts of 294 00:15:11.430 --> 00:15:12.900 keep things simple our header is going to be things that go into the header so to 295 00:15:12.900 --> 00:15:15.270 empty for now although I can sense the keep things simple our header is going to be 296 00:15:15.270 --> 00:15:16.650 a challenge is coming up empty for now although I can sense the 297 00:15:16.650 --> 00:15:19.380 ok let's finish off now and create a challenge is coming up 298 00:15:19.380 --> 00:15:21.810 the body class and end ok let's finish off now and create 299 00:15:21.810 --> 00:15:23.100 the video move on to the next the body class and end 300 00:15:23.100 --> 00:15:32.430 one so class body tag.... the video move on to the next 301 00:15:32.430 --> 00:15:37.350 .... one so class body tag.... 302 00:15:37.350 --> 00:15:40.710 .... .... 303 00:15:40.710 --> 00:15:43.500 ... .... 304 00:15:43.500 --> 00:15:45.360 .... ... 305 00:15:45.360 --> 00:15:49.230 ... .... 306 00:15:49.230 --> 00:15:52.200 ... ... 307 00:15:52.200 --> 00:15:53.370 .... ... 308 00:15:53.370 --> 00:16:05.610 .... .... 309 00:16:05.610 --> 00:16:08.340 alright so let's add method to add the .... 310 00:16:08.340 --> 00:16:11.130 tag we're going to put.... alright so let's add method to add the 311 00:16:11.130 --> 00:16:18.240 .... tag we're going to put.... 312 00:16:18.240 --> 00:16:22.830 ... .... 313 00:16:22.830 --> 00:16:32.700 ... ... 314 00:16:32.700 --> 00:16:33.960 .... ... 315 00:16:33.960 --> 00:16:38.160 .... .... 316 00:16:38.160 --> 00:16:41.730 ... .... 317 00:16:41.730 --> 00:16:44.760 .... ... 318 00:16:44.760 --> 00:16:49.140 ... .... 319 00:16:49.140 --> 00:17:05.820 ... ... 320 00:17:05.820 --> 00:17:08.880 alright let's just discuss this briefly ... 321 00:17:08.880 --> 00:17:12.200 before we end the video so once again for alright let's just discuss this briefly 322 00:17:12.200 --> 00:17:13.890 the body class were inheriting from the before we end the video so once again for 323 00:17:13.890 --> 00:17:16.070 tag class but we initialize the the body class were inheriting from the 324 00:17:16.070 --> 00:17:18.120 contents to an empty string when calling tag class but we initialize the 325 00:17:18.120 --> 00:17:20.100 the super method because we don't what contents to an empty string when calling 326 00:17:20.100 --> 00:17:23.610 the contents to be created just yet and the super method because we don't what 327 00:17:23.610 --> 00:17:24.750 that's because we're going to store all the contents to be created just yet and 328 00:17:24.750 --> 00:17:26.280 the contents and list as you can probably that's because we're going to store all 329 00:17:26.280 --> 00:17:28.740 ascertain in the attribute self dot the contents and list as you can probably 330 00:17:28.740 --> 00:17:31.230 _body_ contents so we ascertain in the attribute self dot 331 00:17:31.230 --> 00:17:32.850 initialize that to an empty list in the _body_ contents so we 332 00:17:32.850 --> 00:17:35.100 constructor can see them doing that on line initialize that to an empty list in the 333 00:17:35.100 --> 00:17:37.980 32 now the add _ tag methods constructor can see them doing that on line 334 00:17:37.980 --> 00:17:40.800 used to add the content to our body and 32 now the add _ tag methods 335 00:17:40.800 --> 00:17:42.330 we give it a name of a tag and the used to add the content to our body and 336 00:17:42.330 --> 00:17:44.460 contents and it creates a new tag we give it a name of a tag and the 337 00:17:44.460 --> 00:17:46.470 instance and appends that to the body contents and it creates a new tag 338 00:17:46.470 --> 00:17:49.110 contents list i'm going to move swiftly instance and appends that to the body 339 00:17:49.110 --> 00:17:51.000 on here but you may already spotted this contents list i'm going to move swiftly 340 00:17:51.000 --> 00:17:53.670 is an example of composition absolutely on here but you may already spotted this 341 00:17:53.670 --> 00:17:54.900 it is and I will come back and talk is an example of composition absolutely 342 00:17:54.900 --> 00:17:57.450 about that more in the next video i want it is and I will come back and talk 343 00:17:57.450 --> 00:17:59.400 to show you the use of composition in about that more in the next video i want 344 00:17:59.400 --> 00:18:01.560 the document first because that's a much to show you the use of composition in 345 00:18:01.560 --> 00:18:04.140 clearer example so moving on in the the document first because that's a much 346 00:18:04.140 --> 00:18:05.820 display method as you can see there on clearer example so moving on in the 347 00:18:05.820 --> 00:18:08.700 line 38 overrides the method from the display method as you can see there on 348 00:18:08.700 --> 00:18:11.190 tag superclass so it builds up the line 38 overrides the method from the 349 00:18:11.190 --> 00:18:13.620 contents attribute by iterating over our tag superclass so it builds up the 350 00:18:13.620 --> 00:18:15.900 body contents list and adding each tag contents attribute by iterating over our 351 00:18:15.900 --> 00:18:18.360 to the contents and once thats done it body contents list and adding each tag 352 00:18:18.360 --> 00:18:20.460 then uses the superclass display method to the contents and once thats done it 353 00:18:20.460 --> 00:18:22.530 to display the body tag with the full then uses the superclass display method 354 00:18:22.530 --> 00:18:23.460 contents to display the body tag with the full 355 00:18:23.460 --> 00:18:25.380 now if you were going to fully implement contents 356 00:18:25.380 --> 00:18:27.630 the header then we could give our head now if you were going to fully implement 357 00:18:27.630 --> 00:18:30.090 class the same ability to add tags and the header then we could give our head 358 00:18:30.090 --> 00:18:32.220 build up its contents in fact we might class the same ability to add tags and 359 00:18:32.220 --> 00:18:34.800 create a special kind of tag class that build up its contents in fact we might 360 00:18:34.800 --> 00:18:36.870 can contain other tags and have both create a special kind of tag class that 361 00:18:36.870 --> 00:18:39.210 head and body inherit from that but we can contain other tags and have both 362 00:18:39.210 --> 00:18:40.920 are trying to keep things simple here head and body inherit from that but we 363 00:18:40.920 --> 00:18:42.660 alright so I'm going to finish the video are trying to keep things simple here 364 00:18:42.660 --> 00:18:44.970 here now in the next video alright so I'm going to finish the video 365 00:18:44.970 --> 00:18:46.260 now that we've got all the classes that here now in the next video 366 00:18:46.260 --> 00:18:49.200 we need to make up our HTML document we now that we've got all the classes that 367 00:18:49.200 --> 00:18:51.570 can create the actual document class so we need to make up our HTML document we 368 00:18:51.570 --> 00:18:58.370 let's work on that in the next video can create the actual document class so