WEBVTT 1 00:00:01.760 --> 00:00:03.919 now towards the end of the last video I 2 00:00:03.919 --> 00:00:06.170 mentioned that if we were going to fully now towards the end of the last video I 3 00:00:06.170 --> 00:00:08.240 implement the header then we could get mentioned that if we were going to fully 4 00:00:08.240 --> 00:00:10.610 our head class the same ability to add implement the header then we could get 5 00:00:10.610 --> 00:00:13.070 tags and build up its contents and in our head class the same ability to add 6 00:00:13.070 --> 00:00:14.960 fact we might create a special kind of tags and build up its contents and in 7 00:00:14.960 --> 00:00:17.539 tag class that can contain other tags fact we might create a special kind of 8 00:00:17.539 --> 00:00:20.390 and then have both head and body inherit tag class that can contain other tags 9 00:00:20.390 --> 00:00:22.130 from that but we are keeping things and then have both head and body inherit 10 00:00:22.130 --> 00:00:23.810 simple here and at this point we've now from that but we are keeping things 11 00:00:23.810 --> 00:00:26.210 got all the classes that make up our simple here and at this point we've now 12 00:00:26.210 --> 00:00:28.670 HTML document and we can create the got all the classes that make up our 13 00:00:28.670 --> 00:00:30.590 document class let's go ahead and do HTML document and we can create the 14 00:00:30.590 --> 00:00:34.249 that in the bottom document class let's go ahead and do 15 00:00:34.249 --> 00:00:44.449 ok so.... that in the bottom 16 00:00:44.449 --> 00:00:46.940 .... ok so.... 17 00:00:46.940 --> 00:01:04.760 .... .... 18 00:01:04.760 --> 00:01:10.730 ... .... 19 00:01:10.730 --> 00:01:13.940 ... ... 20 00:01:13.940 --> 00:01:18.620 ...this init method ... 21 00:01:18.620 --> 00:01:21.350 defines three data attributes to hold ...this init method 22 00:01:21.350 --> 00:01:24.500 the doctype head and body of a HTML defines three data attributes to hold 23 00:01:24.500 --> 00:01:27.380 document now in all three cases a new the doctype head and body of a HTML 24 00:01:27.380 --> 00:01:29.060 object of the appropriate classes document now in all three cases a new 25 00:01:29.060 --> 00:01:31.370 created as you can see and each attribute object of the appropriate classes 26 00:01:31.370 --> 00:01:32.840 is assigned a reference to the new created as you can see and each attribute 27 00:01:32.840 --> 00:01:38.180 object so our HTML dot class is made up is assigned a reference to the new 28 00:01:38.180 --> 00:01:40.970 of instances of the three other classes object so our HTML dot class is made up 29 00:01:40.970 --> 00:01:43.460 so you could say that it's composed of of instances of the three other classes 30 00:01:43.460 --> 00:01:45.590 the three other classes and that's so you could say that it's composed of 31 00:01:45.590 --> 00:01:48.200 composition now this example is pretty the three other classes and that's 32 00:01:48.200 --> 00:01:51.080 uncomplicated because the HTML. class composition now this example is pretty 33 00:01:51.080 --> 00:01:53.840 is entirely composed of other classes it uncomplicated because the HTML. class 34 00:01:53.840 --> 00:01:55.640 doesn't have any data attributes of its is entirely composed of other classes it 35 00:01:55.640 --> 00:01:56.180 own doesn't have any data attributes of its 36 00:01:56.180 --> 00:01:58.250 now that doesn't have to be the case so own 37 00:01:58.250 --> 00:01:59.510 I don't want to give the impression that now that doesn't have to be the case so 38 00:01:59.510 --> 00:02:01.820 composition means creating a class and I don't want to give the impression that 39 00:02:01.820 --> 00:02:03.650 entirely out of other classes composition means creating a class and 40 00:02:03.650 --> 00:02:06.020 the important thing is that our HTML entirely out of other classes 41 00:02:06.020 --> 00:02:08.569 . class contains other classes and the important thing is that our HTML 42 00:02:08.569 --> 00:02:10.549 can make use of the attributes that . class contains other classes and 43 00:02:10.549 --> 00:02:13.069 those classes provide alright i'll can make use of the attributes that 44 00:02:13.069 --> 00:02:14.240 carry on with the code those classes provide alright i'll 45 00:02:14.240 --> 00:02:16.670 so we can see this program working and carry on with the code 46 00:02:16.670 --> 00:02:19.490 how it produces a html doc so we so we can see this program working and 47 00:02:19.490 --> 00:02:22.190 want to add a method.... how it produces a html doc so we 48 00:02:22.190 --> 00:02:23.720 ... want to add a method.... 49 00:02:23.720 --> 00:02:26.930 .... ... 50 00:02:26.930 --> 00:02:32.270 ... .... 51 00:02:32.270 --> 00:02:33.560 .... ... 52 00:02:33.560 --> 00:02:38.240 .... .... 53 00:02:38.240 --> 00:02:44.030 ...we need to .... 54 00:02:44.030 --> 00:02:46.700 add content to our document and HTML ...we need to 55 00:02:46.700 --> 00:02:49.910 content consists of various tags so what add content to our document and HTML 56 00:02:49.910 --> 00:02:52.190 given the html. class and add tag or content consists of various tags so what 57 00:02:52.190 --> 00:02:53.960 add_tagged method to allow given the html. class and add tag or 58 00:02:53.960 --> 00:02:56.540 tags to be added to the document this add_tagged method to allow 59 00:02:56.540 --> 00:02:58.340 method just delegates the job of adding tags to be added to the document this 60 00:02:58.340 --> 00:03:00.920 a tag to its instance of the body class method just delegates the job of adding 61 00:03:00.920 --> 00:03:03.050 the body class takes care of a tag to its instance of the body class 62 00:03:03.050 --> 00:03:05.540 implementing the process of adding a new the body class takes care of 63 00:03:05.540 --> 00:03:09.110 tag to its contents the HTML . class implementing the process of adding a new 64 00:03:09.110 --> 00:03:10.730 just passes on the name of the tag and tag to its contents the HTML . class 65 00:03:10.730 --> 00:03:13.160 the contents as you can see on line 53 just passes on the name of the tag and 66 00:03:13.160 --> 00:03:15.530 now we could have called this method the contents as you can see on line 53 67 00:03:15.530 --> 00:03:17.360 anything add_content for now we could have called this method 68 00:03:17.360 --> 00:03:20.000 example but by giving it the same name anything add_content for 69 00:03:20.000 --> 00:03:22.310 as the class that will actually be doing example but by giving it the same name 70 00:03:22.310 --> 00:03:24.560 the work for us our body class in this as the class that will actually be doing 71 00:03:24.560 --> 00:03:27.290 case we can pass the HTML document the work for us our body class in this 72 00:03:27.290 --> 00:03:29.660 object to any function that adds tags case we can pass the HTML document 73 00:03:29.660 --> 00:03:32.450 now the other thing we want to do with object to any function that adds tags 74 00:03:32.450 --> 00:03:35.450 html objects is display so i'm now the other thing we want to do with 75 00:03:35.450 --> 00:03:42.140 going to add a display method.... html objects is display so i'm 76 00:03:42.140 --> 00:03:45.020 .... going to add a display method.... 77 00:03:45.020 --> 00:03:48.500 .... .... 78 00:03:48.500 --> 00:03:54.140 ... .... 79 00:03:54.140 --> 00:04:03.290 ... ... 80 00:04:03.290 --> 00:04:06.020 .... ... 81 00:04:06.020 --> 00:04:14.000 .... .... 82 00:04:14.000 --> 00:04:18.410 so once again this method delegates most .... 83 00:04:18.410 --> 00:04:20.959 of the work to the classes that contains so once again this method delegates most 84 00:04:20.959 --> 00:04:24.680 so the DTD is displayed by calling the of the work to the classes that contains 85 00:04:24.680 --> 00:04:27.650 doc type instances display method now after so the DTD is displayed by calling the 86 00:04:27.650 --> 00:04:29.900 the DTD everything else is enclosed in doc type instances display method now after 87 00:04:29.900 --> 00:04:33.290 the HTML opening and closing tags on line the DTD everything else is enclosed in 88 00:04:33.290 --> 00:04:36.830 57 and 60 now we could have created a the HTML opening and closing tags on line 89 00:04:36.830 --> 00:04:39.020 class to handle that but that's really 57 and 60 now we could have created a 90 00:04:39.020 --> 00:04:40.370 going to be too far class to handle that but that's really 91 00:04:40.370 --> 00:04:42.320 there's only one html tag in a going to be too far 92 00:04:42.320 --> 00:04:44.540 document and hard coding like this is a there's only one html tag in a 93 00:04:44.540 --> 00:04:47.360 much simpler solution now the display document and hard coding like this is a 94 00:04:47.360 --> 00:04:49.700 the remaining content is also delegated much simpler solution now the display 95 00:04:49.700 --> 00:04:52.610 to the appropriate classes so apart from the remaining content is also delegated 96 00:04:52.610 --> 00:04:54.440 including the opening and closing HTML to the appropriate classes so apart from 97 00:04:54.440 --> 00:04:57.200 tag our documents display method including the opening and closing HTML 98 00:04:57.200 --> 00:04:58.850 doesn't have a lot to do tag our documents display method 99 00:04:58.850 --> 00:05:00.560 once again we could have called this doesn't have a lot to do 100 00:05:00.560 --> 00:05:02.600 method anything but by calling it once again we could have called this 101 00:05:02.600 --> 00:05:05.090 display it matches the corresponding method anything but by calling it 102 00:05:05.090 --> 00:05:07.190 method in the classes its composed of display it matches the corresponding 103 00:05:07.190 --> 00:05:09.980 by calling the method display it can then method in the classes its composed of 104 00:05:09.980 --> 00:05:12.950 be used by any function that displays by calling the method display it can then 105 00:05:12.950 --> 00:05:16.580 tag objects in fact the method it has are be used by any function that displays 106 00:05:16.580 --> 00:05:18.320 exactly the same as the method in the tag objects in fact the method it has are 107 00:05:18.320 --> 00:05:22.010 body class so our HTML dot class is now exactly the same as the method in the 108 00:05:22.010 --> 00:05:25.040 displaying polymorphic behavior it is a body class so our HTML dot class is now 109 00:05:25.040 --> 00:05:27.500 html doc but it can also be used displaying polymorphic behavior it is a 110 00:05:27.500 --> 00:05:30.320 in place of a body object it can even be html doc but it can also be used 111 00:05:30.320 --> 00:05:31.850 used in place of any of our tag in place of a body object it can even be 112 00:05:31.850 --> 00:05:34.700 subclasses when pass to functions that used in place of any of our tag 113 00:05:34.700 --> 00:05:37.010 just need to display method so we've subclasses when pass to functions that 114 00:05:37.010 --> 00:05:39.020 implemented polymorphism without using just need to display method so we've 115 00:05:39.020 --> 00:05:41.360 inheritance we've used composition implemented polymorphism without using 116 00:05:41.360 --> 00:05:44.330 instead now the program itself does use inheritance we've used composition 117 00:05:44.330 --> 00:05:46.610 inheritance all our other classes instead now the program itself does use 118 00:05:46.610 --> 00:05:49.340 inherit from tagged but the HTML doc type inheritance all our other classes 119 00:05:49.340 --> 00:05:52.100 isn't a subclass of tag it provides the inherit from tagged but the HTML doc type 120 00:05:52.100 --> 00:05:54.470 same methods as their tags but does so isn't a subclass of tag it provides the 121 00:05:54.470 --> 00:05:56.510 by defining methods with the same name same methods as their tags but does so 122 00:05:56.510 --> 00:05:59.240 and then delegating the implementation by defining methods with the same name 123 00:05:59.240 --> 00:06:01.100 of those methods to the classes that is and then delegating the implementation 124 00:06:01.100 --> 00:06:03.470 composed of alright so let's see this of those methods to the classes that is 125 00:06:03.470 --> 00:06:05.479 running to make sure that this theory composed of alright so let's see this 126 00:06:05.479 --> 00:06:07.190 that we've been talking about does work running to make sure that this theory 127 00:06:07.190 --> 00:06:10.550 in practice so we're going to add a that we've been talking about does work 128 00:06:10.550 --> 00:06:12.650 method down here.... in practice so we're going to add a 129 00:06:12.650 --> 00:06:15.229 .... method down here.... 130 00:06:15.229 --> 00:06:18.320 .... .... 131 00:06:18.320 --> 00:06:21.410 ... .... 132 00:06:21.410 --> 00:06:24.150 .... ... 133 00:06:24.150 --> 00:06:29.670 .... .... 134 00:06:29.670 --> 00:06:33.450 ... .... 135 00:06:33.450 --> 00:06:38.700 .... ... 136 00:06:38.700 --> 00:06:42.120 .... .... 137 00:06:42.120 --> 00:06:44.220 ... .... 138 00:06:44.220 --> 00:06:46.860 .... ... 139 00:06:46.860 --> 00:06:50.370 .... .... 140 00:06:50.370 --> 00:06:54.600 ... .... 141 00:06:54.600 --> 00:07:23.280 ... ... 142 00:07:23.280 --> 00:07:26.880 ...creating a new ... 143 00:07:26.880 --> 00:07:29.250 HTML object and then were assigning the ...creating a new 144 00:07:29.250 --> 00:07:31.470 reference to it to a very variable HTML object and then were assigning the 145 00:07:31.470 --> 00:07:34.230 called my_page so next we reference to it to a very variable 146 00:07:34.230 --> 00:07:36.540 use this add_tag method to add a called my_page so next we 147 00:07:36.540 --> 00:07:39.030 heading and a subheading now the add_tag use this add_tag method to add a 148 00:07:39.030 --> 00:07:41.190 method remember just heading and a subheading now the add_tag 149 00:07:41.190 --> 00:07:43.020 delegate to the body classes add method remember just 150 00:07:43.020 --> 00:07:44.910 underscore tag method so these elements delegate to the body classes add 151 00:07:44.910 --> 00:07:46.620 will really be added to the body section underscore tag method so these elements 152 00:07:46.620 --> 00:07:48.990 so effectively we're building up the will really be added to the body section 153 00:07:48.990 --> 00:07:51.300 document by calling the add_tag so effectively we're building up the 154 00:07:51.300 --> 00:07:53.130 method to add the content that we want document by calling the add_tag 155 00:07:53.130 --> 00:07:55.230 when we done the last line we're calling method to add the content that we want 156 00:07:55.230 --> 00:07:57.030 the display method to display the when we done the last line we're calling 157 00:07:57.030 --> 00:07:58.200 finished document the display method to display the 158 00:07:58.200 --> 00:08:00.090 alright so let's just run the program finished document 159 00:08:00.090 --> 00:08:02.760 need to put a colon in that line alright so let's just run the program 160 00:08:02.760 --> 00:08:06.960 correct on line are 63 and run this need to put a colon in that line 161 00:08:06.960 --> 00:08:09.480 now correct on line are 63 and run this 162 00:08:09.480 --> 00:08:11.520 and we got an error over here and we can see now 163 00:08:11.520 --> 00:08:13.170 that the typo looks to me that I've use and we got an error over here and we can see 164 00:08:13.170 --> 00:08:16.230 start _ capital T so just click on that the typo looks to me that I've use 165 00:08:16.230 --> 00:08:18.150 that to go to the link that's the start _ capital T so just click on 166 00:08:18.150 --> 00:08:19.800 problem you can see added a capital T that to go to the link that's the 167 00:08:19.800 --> 00:08:22.800 i'll make the lowercase T because problem you can see added a capital T 168 00:08:22.800 --> 00:08:25.350 obviously the the attributes i'll make the lowercase T because 169 00:08:25.350 --> 00:08:27.540 should be or have rather a lowercase T obviously the the attributes 170 00:08:27.540 --> 00:08:28.410 in its name should be or have rather a lowercase T 171 00:08:28.410 --> 00:08:31.860 let's just try running it again and this in its name 172 00:08:31.860 --> 00:08:33.390 time we seem to fix it which is much let's just try running it again and this 173 00:08:33.390 --> 00:08:34.300 better time we seem to fix it which is much 174 00:08:34.300 --> 00:08:36.459 alright so you can see now if better 175 00:08:36.459 --> 00:08:38.979 you familiar with HTML that this is now alright so you can see now if 176 00:08:38.979 --> 00:08:41.890 perfectly formed HTML code you familiar with HTML that this is now 177 00:08:41.890 --> 00:08:43.510 now it's not as readable as it would be perfectly formed HTML code 178 00:08:43.510 --> 00:08:45.820 if a human it type it manually but line now it's not as readable as it would be 179 00:08:45.820 --> 00:08:47.830 breaks are ignored in HTML documents if a human it type it manually but line 180 00:08:47.830 --> 00:08:49.870 there only added to make it easy for breaks are ignored in HTML documents 181 00:08:49.870 --> 00:08:52.510 humans to read if you're not familiar there only added to make it easy for 182 00:08:52.510 --> 00:08:54.730 with HTML the real test will be if it humans to read if you're not familiar 183 00:08:54.730 --> 00:08:57.399 displays correctly in a browser so let's with HTML the real test will be if it 184 00:08:57.399 --> 00:08:58.870 actually make a change so that we could displays correctly in a browser so let's 185 00:08:58.870 --> 00:09:01.329 write the document out to a file instead actually make a change so that we could 186 00:09:01.329 --> 00:09:03.279 of just printing it now the only changes write the document out to a file instead 187 00:09:03.279 --> 00:09:05.589 we need to make are to the three display of just printing it now the only changes 188 00:09:05.589 --> 00:09:07.630 methods i'm going to start with the base we need to make are to the three display 189 00:09:07.630 --> 00:09:09.970 class the tag classes go back up and methods i'm going to start with the base 190 00:09:09.970 --> 00:09:12.190 look at that class the tag classes go back up and 191 00:09:12.190 --> 00:09:14.320 so the display method here on the line look at that 192 00:09:14.320 --> 00:09:17.079 11 we want to change that what we're so the display method here on the line 193 00:09:17.079 --> 00:09:19.690 going to do is add another parameter here 11 we want to change that what we're 194 00:09:19.690 --> 00:09:21.700 so after the display itself... going to do is add another parameter here 195 00:09:21.700 --> 00:09:26.019 .... so after the display itself... 196 00:09:26.019 --> 00:09:31.480 .... .... 197 00:09:31.480 --> 00:09:34.899 ok so we've added a named parameter called .... 198 00:09:34.899 --> 00:09:37.240 file that matches the file parameter of ok so we've added a named parameter called 199 00:09:37.240 --> 00:09:39.310 the print function so we need to file that matches the file parameter of 200 00:09:39.310 --> 00:09:43.180 do the same in the body class down here the print function so we need to 201 00:09:43.180 --> 00:09:44.740 under display in the body class on line do the same in the body class down here 202 00:09:44.740 --> 00:09:50.829 38.... under display in the body class on line 203 00:09:50.829 --> 00:09:54.310 ... 38.... 204 00:09:54.310 --> 00:09:57.190 .... ... 205 00:09:57.190 --> 00:10:00.550 alright so we added a filename parameter .... 206 00:10:00.550 --> 00:10:02.589 as you can see there to this method as alright so we added a filename parameter 207 00:10:02.589 --> 00:10:04.630 well and then provide the default value as you can see there to this method as 208 00:10:04.630 --> 00:10:08.110 of none so if a file isn't specified the well and then provide the default value 209 00:10:08.110 --> 00:10:09.520 class will be printed to the screen of none so if a file isn't specified the 210 00:10:09.520 --> 00:10:12.310 effectively alright so now the class will be printed to the screen 211 00:10:12.310 --> 00:10:14.740 display method of the html. class effectively alright so now the 212 00:10:14.740 --> 00:10:18.730 ok so down here in the display method display method of the html. class 213 00:10:18.730 --> 00:10:23.770 we put.... ok so down here in the display method 214 00:10:23.770 --> 00:10:26.199 .... we put.... 215 00:10:26.199 --> 00:10:28.329 ... .... 216 00:10:28.329 --> 00:10:32.649 .... ... 217 00:10:32.649 --> 00:10:35.410 ... .... 218 00:10:35.410 --> 00:10:54.769 ... ... 219 00:10:54.769 --> 00:10:57.709 ....so now that we've done that we can ... 220 00:10:57.709 --> 00:10:59.690 now send the output to a file if we want ....so now that we've done that we can 221 00:10:59.690 --> 00:11:01.910 to using the technique we saw back in now send the output to a file if we want 222 00:11:01.910 --> 00:11:04.279 Section 10 when we're writing to files to using the technique we saw back in 223 00:11:04.279 --> 00:11:07.760 so let's end this video here now in the Section 10 when we're writing to files 224 00:11:07.760 --> 00:11:09.589 next video we'll come back and test so let's end this video here now in the 225 00:11:09.589 --> 00:11:10.940 this will talk a little bit more about next video we'll come back and test 226 00:11:10.940 --> 00:11:13.190 composition and then we'll move on to a this will talk a little bit more about 227 00:11:13.190 --> 00:11:20.050 challenge see you in the next video composition and then we'll move on to a