WEBVTT 1 00:00:01.820 --> 00:00:03.980 alright so the changes we made at the 2 00:00:03.980 --> 00:00:06.290 end of the last video enable us to send alright so the changes we made at the 3 00:00:06.290 --> 00:00:07.910 the output to a file if you want to end of the last video enable us to send 4 00:00:07.910 --> 00:00:10.009 using the technique we saw back in the output to a file if you want to 5 00:00:10.009 --> 00:00:12.080 Section 10 when we were writing to using the technique we saw back in 6 00:00:12.080 --> 00:00:13.190 files Section 10 when we were writing to 7 00:00:13.190 --> 00:00:14.749 alright so let's make sure that it still files 8 00:00:14.749 --> 00:00:16.369 works and that it looks the same as it did alright so let's make sure that it still 9 00:00:16.369 --> 00:00:18.679 before so now we can send the output to works and that it looks the same as it did 10 00:00:18.679 --> 00:00:20.689 a file and see how it displays in a before so now we can send the output to 11 00:00:20.689 --> 00:00:22.730 browser so lets actually do that so what a file and see how it displays in a 12 00:00:22.730 --> 00:00:25.400 we're going to do is after the browser so lets actually do that so what 13 00:00:25.400 --> 00:00:28.609 tag the paragraph tag we're going to do we're going to do is after the 14 00:00:28.609 --> 00:00:35.690 .... tag the paragraph tag we're going to do 15 00:00:35.690 --> 00:00:41.690 .... .... 16 00:00:41.690 --> 00:00:44.390 ... .... 17 00:00:44.390 --> 00:00:47.600 .... ... 18 00:00:47.600 --> 00:00:51.199 ... .... 19 00:00:51.199 --> 00:00:57.199 .... ... 20 00:00:57.199 --> 00:00:59.149 and we'll just open the project pane so .... 21 00:00:59.149 --> 00:01:00.170 we can see that the file gets and we'll just open the project pane so 22 00:01:00.170 --> 00:01:02.359 created for us now if you are using we can see that the file gets 23 00:01:02.359 --> 00:01:03.980 linux or mac do make sure you add the created for us now if you are using 24 00:01:03.980 --> 00:01:06.740 dot HTML file extension even if you linux or mac do make sure you add the 25 00:01:06.740 --> 00:01:07.909 wouldn't normally do that and I'll dot HTML file extension even if you 26 00:01:07.909 --> 00:01:09.530 explain why in a minute wouldn't normally do that and I'll 27 00:01:09.530 --> 00:01:11.119 now we can send the output of the explain why in a minute 28 00:01:11.119 --> 00:01:13.520 display method to a file by adding test now we can send the output of the 29 00:01:13.520 --> 00:01:16.460 _doc as the named perimeter in the display method to a file by adding test 30 00:01:16.460 --> 00:01:18.710 call to display and you saw me do that on line _doc as the named perimeter in the 31 00:01:18.710 --> 00:01:23.900 69 so let's just run this you can call to display and you saw me do that on line 32 00:01:23.900 --> 00:01:25.850 see that was very quick and then the 69 so let's just run this you can 33 00:01:25.850 --> 00:01:29.450 file test.HTML appeared now intelliJ see that was very quick and then the 34 00:01:29.450 --> 00:01:31.759 understands about HTML so i can file test.HTML appeared now intelliJ 35 00:01:31.759 --> 00:01:33.170 right-click the test file in the project understands about HTML so i can 36 00:01:33.170 --> 00:01:37.460 pane the context menu their is an open in right-click the test file in the project 37 00:01:37.460 --> 00:01:40.640 browser down here and that's why I pane the context menu their is an open in 38 00:01:40.640 --> 00:01:42.020 mentioned that you should include the browser down here and that's why I 39 00:01:42.020 --> 00:01:44.540 file extension linux and osx don't mentioned that you should include the 40 00:01:44.540 --> 00:01:46.340 rely on the file extension to decide file extension linux and osx don't 41 00:01:46.340 --> 00:01:47.869 what to do with the file but rely on the file extension to decide 42 00:01:47.869 --> 00:01:49.399 intelliJ has adopted the windows what to do with the file but 43 00:01:49.399 --> 00:01:51.229 approach and does use the file extension intelliJ has adopted the windows 44 00:01:51.229 --> 00:01:54.200 so if the file doesn't have a dot HTM or approach and does use the file extension 45 00:01:54.200 --> 00:01:56.960 dot HTML extension then you won't get so if the file doesn't have a dot HTM or 46 00:01:56.960 --> 00:01:58.939 the option to open in your browser dot HTML extension then you won't get 47 00:01:58.939 --> 00:02:01.189 alright so in my case though i'm going the option to open in your browser 48 00:02:01.189 --> 00:02:02.509 to choose chrome which is the one that I alright so in my case though i'm going 49 00:02:02.509 --> 00:02:03.979 normally do when i'm recording videos to choose chrome which is the one that I 50 00:02:03.979 --> 00:02:06.229 you can choose the default normally do when i'm recording videos 51 00:02:06.229 --> 00:02:09.080 browser and we can see that it's you can choose the default 52 00:02:09.080 --> 00:02:10.580 actually popped up now and it's working browser and we can see that it's 53 00:02:10.580 --> 00:02:11.690 quite nicely actually popped up now and it's working 54 00:02:11.690 --> 00:02:14.600 alright so that's composition now we've quite nicely 55 00:02:14.600 --> 00:02:15.420 used both alright so that's composition now we've 56 00:02:15.420 --> 00:02:17.700 composition and inheritance in this program used both 57 00:02:17.700 --> 00:02:19.680 so it's a good example of the composition and inheritance in this program 58 00:02:19.680 --> 00:02:21.660 differences between them and when you so it's a good example of the 59 00:02:21.660 --> 00:02:24.510 use each one so getting back to our code differences between them and when you 60 00:02:24.510 --> 00:02:30.450 now our basic classes all inherit from use each one so getting back to our code 61 00:02:30.450 --> 00:02:32.280 tagged and when we talk about head for now our basic classes all inherit from 62 00:02:32.280 --> 00:02:35.459 example would say that head is a tag tagged and when we talk about head for 63 00:02:35.459 --> 00:02:38.280 similarly body is a tag and so is example would say that head is a tag 64 00:02:38.280 --> 00:02:40.620 doctype although doc type are slightly similarly body is a tag and so is 65 00:02:40.620 --> 00:02:42.510 different kind of tag it doesn't have a doctype although doc type are slightly 66 00:02:42.510 --> 00:02:44.790 corresponding end tag so whenever you different kind of tag it doesn't have a 67 00:02:44.790 --> 00:02:46.230 have a relationship that can be corresponding end tag so whenever you 68 00:02:46.230 --> 00:02:48.269 described using is a that's an have a relationship that can be 69 00:02:48.269 --> 00:02:49.470 indication that you should consider described using is a that's an 70 00:02:49.470 --> 00:02:52.260 using inheritance to model the objects indication that you should consider 71 00:02:52.260 --> 00:02:54.239 composition is used when the using inheritance to model the objects 72 00:02:54.239 --> 00:02:57.060 relationship is described as a has a a composition is used when the 73 00:02:57.060 --> 00:03:00.299 document has a doctype and has a body so relationship is described as a has a a 74 00:03:00.299 --> 00:03:02.220 composition is more appropriate to model document has a doctype and has a body so 75 00:03:02.220 --> 00:03:03.330 the document composition is more appropriate to model 76 00:03:03.330 --> 00:03:04.799 ok there's another example of the document 77 00:03:04.799 --> 00:03:06.630 composition being used in our body class ok there's another example of 78 00:03:06.630 --> 00:03:09.390 so let's have a look at that HTML composition being used in our body class 79 00:03:09.390 --> 00:03:10.980 doc object has to contain a so let's have a look at that HTML 80 00:03:10.980 --> 00:03:14.459 doctype a head tag and a body tag so it's doc object has to contain a 81 00:03:14.459 --> 00:03:16.860 effectively not an HTML document without doctype a head tag and a body tag so it's 82 00:03:16.860 --> 00:03:17.580 them effectively not an HTML document without 83 00:03:17.580 --> 00:03:19.709 so these three components are created them 84 00:03:19.709 --> 00:03:21.480 when each instance of the class is so these three components are created 85 00:03:21.480 --> 00:03:24.959 created in the init method you can see when each instance of the class is 86 00:03:24.959 --> 00:03:26.280 its doing that down here starting on line created in the init method you can see 87 00:03:26.280 --> 00:03:29.579 47 now body object has any number of its doing that down here starting on line 88 00:03:29.579 --> 00:03:32.609 tags and maybe empty that would make for 47 now body object has any number of 89 00:03:32.609 --> 00:03:34.680 a very interesting document but it would tags and maybe empty that would make for 90 00:03:34.680 --> 00:03:37.709 actually conform to the specification so a very interesting document but it would 91 00:03:37.709 --> 00:03:39.570 we don't create any objects when body actually conform to the specification so 92 00:03:39.570 --> 00:03:41.910 instances are created instead we just we don't create any objects when body 93 00:03:41.910 --> 00:03:44.220 create an empty list ready to contain instances are created instead we just 94 00:03:44.220 --> 00:03:47.250 the tags when they're added you can see create an empty list ready to contain 95 00:03:47.250 --> 00:03:49.620 that code for that here on line 32 now the tags when they're added you can see 96 00:03:49.620 --> 00:03:51.600 when a tag is added to the body by that code for that here on line 32 now 97 00:03:51.600 --> 00:03:53.400 calling the body classes add_ when a tag is added to the body by 98 00:03:53.400 --> 00:03:56.489 tag method a new tag objects created then calling the body classes add_ 99 00:03:56.489 --> 00:03:59.160 appended to the list now this is also tag method a new tag objects created then 100 00:03:59.160 --> 00:04:01.980 composition but now the body class has appended to the list now this is also 101 00:04:01.980 --> 00:04:04.769 its own attributes isn't just composed composition but now the body class has 102 00:04:04.769 --> 00:04:06.510 of its composite classes its own attributes isn't just composed 103 00:04:06.510 --> 00:04:08.220 it has an underscore body _ of its composite classes 104 00:04:08.220 --> 00:04:10.829 contents data attribute and a method it has an underscore body _ 105 00:04:10.829 --> 00:04:12.690 called add underscore tag contents data attribute and a method 106 00:04:12.690 --> 00:04:14.459 alright so at this point anything else called add underscore tag 107 00:04:14.459 --> 00:04:16.620 to say about this wil all be repetition alright so at this point anything else 108 00:04:16.620 --> 00:04:19.019 so it's time for a challenge to to say about this wil all be repetition 109 00:04:19.019 --> 00:04:21.090 consolidate what we covered to give you so it's time for a challenge to 110 00:04:21.090 --> 00:04:23.669 a bit of a chance to apply it at the consolidate what we covered to give you 111 00:04:23.669 --> 00:04:26.039 moment ahead class doesn't create a a bit of a chance to apply it at the 112 00:04:26.039 --> 00:04:28.350 document header with anything in it moment ahead class doesn't create a 113 00:04:28.350 --> 00:04:30.120 so your challenge is to modify the document header with anything in it 114 00:04:30.120 --> 00:04:32.670 program so that the head class can so your challenge is to modify the 115 00:04:32.670 --> 00:04:35.790 include a title tag and your HTML should program so that the head class can 116 00:04:35.790 --> 00:04:37.050 look something like this include a title tag and your HTML should 117 00:04:37.050 --> 00:04:38.760 although there's no need to include look something like this 118 00:04:38.760 --> 00:04:40.680 line-breaks indenting I've just done although there's no need to include 119 00:04:40.680 --> 00:04:42.840 that to make it easy to read but the line-breaks indenting I've just done 120 00:04:42.840 --> 00:04:45.030 text for the title will be passed to the that to make it easy to read but the 121 00:04:45.030 --> 00:04:47.580 html dot classes init method where text for the title will be passed to the 122 00:04:47.580 --> 00:04:49.860 the documents created alright so that's html dot classes init method where 123 00:04:49.860 --> 00:04:51.960 the challenge see how you go with that the documents created alright so that's 124 00:04:51.960 --> 00:04:53.760 pause the video and I'll see you when the challenge see how you go with that 125 00:04:53.760 --> 00:04:58.230 you get back ok so the basic approach pause the video and I'll see you when 126 00:04:58.230 --> 00:05:00.000 this challenge will probably be the same you get back ok so the basic approach 127 00:05:00.000 --> 00:05:02.370 for all solutions but you may well have this challenge will probably be the same 128 00:05:02.370 --> 00:05:03.960 a different implementation to my for all solutions but you may well have 129 00:05:03.960 --> 00:05:06.450 solution as always that's fine a different implementation to my 130 00:05:06.450 --> 00:05:09.330 the real test is does it work if you get solution as always that's fine 131 00:05:09.330 --> 00:05:11.010 the correct HTML produced then the real test is does it work if you get 132 00:05:11.010 --> 00:05:12.180 congratulations the correct HTML produced then 133 00:05:12.180 --> 00:05:15.180 alright so if you read through the basic congratulations 134 00:05:15.180 --> 00:05:18.210 HTML structure that we looked in the alright so if you read through the basic 135 00:05:18.210 --> 00:05:20.100 browser earlier you may have noticed HTML structure that we looked in the 136 00:05:20.100 --> 00:05:21.360 that the head can contain a few browser earlier you may have noticed 137 00:05:21.360 --> 00:05:23.520 different tags so you may have made the that the head can contain a few 138 00:05:23.520 --> 00:05:27.060 head class behave like a body class with different tags so you may have made the 139 00:05:27.060 --> 00:05:29.130 an add_tag method to add new content head class behave like a body class with 140 00:05:29.130 --> 00:05:31.710 to the head element that's fine it's an add_tag method to add new content 141 00:05:31.710 --> 00:05:33.720 probably the way you do things so that to the head element that's fine it's 142 00:05:33.720 --> 00:05:36.450 the program correctly reflects the HTML probably the way you do things so that 143 00:05:36.450 --> 00:05:39.090 specification the challenge we asked for the program correctly reflects the HTML 144 00:05:39.090 --> 00:05:41.580 a title so for my solution i'm just specification the challenge we asked for 145 00:05:41.580 --> 00:05:43.620 going to add a title and nothing more a title so for my solution i'm just 146 00:05:43.620 --> 00:05:45.240 so the first step is to modify the head going to add a title and nothing more 147 00:05:45.240 --> 00:05:49.560 class and we need to modify the init so the first step is to modify the head 148 00:05:49.560 --> 00:05:51.900 method to take another argument which class and we need to modify the init 149 00:05:51.900 --> 00:05:53.910 effectively will be the title going to method to take another argument which 150 00:05:53.910 --> 00:05:57.210 come up here we're going to put.... effectively will be the title going to 151 00:05:57.210 --> 00:06:01.860 .... come up here we're going to put.... 152 00:06:01.860 --> 00:06:05.520 ... .... 153 00:06:05.520 --> 00:06:09.630 ... ... 154 00:06:09.630 --> 00:06:12.840 .... ... 155 00:06:12.840 --> 00:06:14.100 ... .... 156 00:06:14.100 --> 00:06:16.440 ... ... 157 00:06:16.440 --> 00:06:18.540 .... ... 158 00:06:18.540 --> 00:06:23.700 ... .... 159 00:06:23.700 --> 00:06:27.540 ....so this creates a new ... 160 00:06:27.540 --> 00:06:30.750 tag with the name title and the contents ....so this creates a new 161 00:06:30.750 --> 00:06:32.760 being the text that was passed in to the tag with the name title and the contents 162 00:06:32.760 --> 00:06:35.430 init method now the head contents are being the text that was passed in to the 163 00:06:35.430 --> 00:06:37.560 then set to this the string init method now the head contents are 164 00:06:37.560 --> 00:06:39.810 representation of this new tag now we then set to this the string 165 00:06:39.810 --> 00:06:41.740 can improve that slightly representation of this new tag now we 166 00:06:41.740 --> 00:06:43.539 if the title doesn't contain any text can improve that slightly 167 00:06:43.539 --> 00:06:45.130 then we really don't want an empty tag if the title doesn't contain any text 168 00:06:45.130 --> 00:06:47.949 inside the head so we can give the title then we really don't want an empty tag 169 00:06:47.949 --> 00:06:50.199 parameter a default value than test inside the head so we can give the title 170 00:06:50.199 --> 00:06:52.690 this before creating the tag parameter a default value than test 171 00:06:52.690 --> 00:06:54.340 let's go ahead and do that i'm going to this before creating the tag 172 00:06:54.340 --> 00:06:58.810 put.... let's go ahead and do that i'm going to 173 00:06:58.810 --> 00:07:00.099 ... put.... 174 00:07:00.099 --> 00:07:10.720 ... ... 175 00:07:10.720 --> 00:07:12.160 alright next thing we need to do is ... 176 00:07:12.160 --> 00:07:15.940 modify the HTML dot class now first it alright next thing we need to do is 177 00:07:15.940 --> 00:07:18.069 needs a parameter to the init method to modify the HTML dot class now first it 178 00:07:18.069 --> 00:07:20.919 accept the title and we'll use a named needs a parameter to the init method to 179 00:07:20.919 --> 00:07:22.479 parameter with the default value here as accept the title and we'll use a named 180 00:07:22.479 --> 00:07:25.150 well that way a document can be created parameter with the default value here as 181 00:07:25.150 --> 00:07:28.630 without providing a title so come well that way a document can be created 182 00:07:28.630 --> 00:07:33.550 down to the html doc the init Method... without providing a title so come 183 00:07:33.550 --> 00:07:35.860 ... down to the html doc the init Method... 184 00:07:35.860 --> 00:07:41.169 ... ... 185 00:07:41.169 --> 00:07:45.159 ...now the html . ... 186 00:07:45.159 --> 00:07:46.780 class doesn't have to do anything with ...now the html . 187 00:07:46.780 --> 00:07:48.969 the title it's just passing it on to the class doesn't have to do anything with 188 00:07:48.969 --> 00:07:50.979 head class when it creates a new head the title it's just passing it on to the 189 00:07:50.979 --> 00:07:53.080 object and that should be all we need to head class when it creates a new head 190 00:07:53.080 --> 00:07:55.630 do I'm going to start by making sure we haven't object and that should be all we need to 191 00:07:55.630 --> 00:07:57.250 broken anything so i'm going to run the do I'm going to start by making sure we haven't 192 00:07:57.250 --> 00:08:01.509 program if we don't got any errors that is a broken anything so i'm going to run the 193 00:08:01.509 --> 00:08:03.940 good sign and what i can do is open the program if we don't got any errors that is a 194 00:08:03.940 --> 00:08:05.949 project pane I can also double-click good sign and what i can do is open the 195 00:08:05.949 --> 00:08:08.349 that if i wanted to open the HTML file project pane I can also double-click 196 00:08:08.349 --> 00:08:10.030 in the default browser but I'm going to that if i wanted to open the HTML file 197 00:08:10.030 --> 00:08:12.340 right click it open a browser and choose in the default browser but I'm going to 198 00:08:12.340 --> 00:08:16.270 chrome again that's it opening up now right click it open a browser and choose 199 00:08:16.270 --> 00:08:18.940 in a new tab if we have a look at the chrome again that's it opening up now 200 00:08:18.940 --> 00:08:22.750 HTML so far so good we haven't past a title in a new tab if we have a look at the 201 00:08:22.750 --> 00:08:24.550 in so we haven't got a title and the HTML so far so good we haven't past a title 202 00:08:24.550 --> 00:08:26.319 head tags up there on line three in so we haven't got a title and the 203 00:08:26.319 --> 00:08:29.199 so that's good that's working so let's head tags up there on line three 204 00:08:29.199 --> 00:08:31.090 see now if it works when we do passing a so that's good that's working so let's 205 00:08:31.090 --> 00:08:32.919 title and i'll provide that when we see now if it works when we do passing a 206 00:08:32.919 --> 00:08:36.159 create the HTML doc instance go back title and i'll provide that when we 207 00:08:36.159 --> 00:08:37.060 to the code again create the HTML doc instance go back 208 00:08:37.060 --> 00:08:40.839 so where we need to change this is on line to the code again 209 00:08:40.839 --> 00:08:44.500 67 let's just make that.... so where we need to change this is on line 210 00:08:44.500 --> 00:08:48.579 ....all right we'll run 67 let's just make that.... 211 00:08:48.579 --> 00:08:53.709 again in a browser or open in browser and ....all right we'll run 212 00:08:53.709 --> 00:08:55.089 look at the source again in a browser or open in browser and 213 00:08:55.089 --> 00:08:58.269 okay for some reason we haven't got a look at the source 214 00:08:58.269 --> 00:08:59.439 a title lets just go back and check our okay for some reason we haven't got a 215 00:08:59.439 --> 00:09:04.449 code ok looking at the code a title lets just go back and check our 216 00:09:04.449 --> 00:09:06.069 definitely got the title in there and we go code ok looking at the code 217 00:09:06.069 --> 00:09:08.620 back down I'll go back up i should say definitely got the title in there and we go 218 00:09:08.620 --> 00:09:09.490 to the head back down I'll go back up i should say 219 00:09:09.490 --> 00:09:12.220 we've definitely got the title to the head 220 00:09:12.220 --> 00:09:15.069 arguments showing init method and we're we've definitely got the title 221 00:09:15.069 --> 00:09:18.129 definitely creating a tag and that should all arguments showing init method and we're 222 00:09:18.129 --> 00:09:19.839 be ok as far as I'm concerns just try definitely creating a tag and that should all 223 00:09:19.839 --> 00:09:24.370 running it again and go back to browser be ok as far as I'm concerns just try 224 00:09:24.370 --> 00:09:25.930 what we need to do is need to open it running it again and go back to browser 225 00:09:25.930 --> 00:09:31.809 again open browser Chrome again let's what we need to do is need to open it 226 00:09:31.809 --> 00:09:34.720 just look at the page source and it is again open browser Chrome again let's 227 00:09:34.720 --> 00:09:36.579 .... just look at the page source and it is 228 00:09:36.579 --> 00:09:40.089 ... .... 229 00:09:40.089 --> 00:09:42.670 ... ... 230 00:09:42.670 --> 00:09:47.019 ...ok so false alarm ... 231 00:09:47.019 --> 00:09:49.059 that was all working correctly and with ...ok so false alarm 232 00:09:49.059 --> 00:09:51.550 now got the test html containing a that was all working correctly and with 233 00:09:51.550 --> 00:09:54.699 title tag inside the head and by the way now got the test html containing a 234 00:09:54.699 --> 00:09:55.839 the other way we could have checked for title tag inside the head and by the way 235 00:09:55.839 --> 00:09:58.240 that is if we just go back and the other way we could have checked for 236 00:09:58.240 --> 00:10:02.230 closed down these view sources depending on that is if we just go back and 237 00:10:02.230 --> 00:10:04.240 the browser you can actually see the closed down these view sources depending on 238 00:10:04.240 --> 00:10:06.939 title in the browser bar but I can't the way the browser you can actually see the 239 00:10:06.939 --> 00:10:08.259 chrome is configured on my title in the browser bar but I can't the way 240 00:10:08.259 --> 00:10:10.029 computer right now that would be a chrome is configured on my 241 00:10:10.029 --> 00:10:12.100 second way of doing it anyway because in computer right now that would be a 242 00:10:12.100 --> 00:10:13.720 my case I'm still just seeing the URL of second way of doing it anyway because in 243 00:10:13.720 --> 00:10:18.279 the document but depending on how your my case I'm still just seeing the URL of 244 00:10:18.279 --> 00:10:20.379 browser is configured you probably see the document but depending on how your 245 00:10:20.379 --> 00:10:22.179 the title in the browser's address bar browser is configured you probably see 246 00:10:22.179 --> 00:10:22.959 anyway the title in the browser's address bar 247 00:10:22.959 --> 00:10:25.179 alright so that's it that's composition anyway 248 00:10:25.179 --> 00:10:27.339 in action in the next video we're going alright so that's it that's composition 249 00:10:27.339 --> 00:10:28.389 to look at something that's often in action in the next video we're going 250 00:10:28.389 --> 00:10:30.100 described as a weaker form of to look at something that's often 251 00:10:30.100 --> 00:10:33.069 composition and that's aggregation see described as a weaker form of 252 00:10:33.069 --> 00:10:38.819 you in the next video composition and that's aggregation see