1 00:00:01,210 --> 00:00:05,400 In the last video we reflected our interface to have a little bit more generic name. 2 00:00:05,410 --> 00:00:07,790 We did the same thing with our function down here. 3 00:00:07,850 --> 00:00:11,090 So now I want to do something kind of interesting inside this file. 4 00:00:11,110 --> 00:00:17,890 Right now we've got a object called old Civic on a define another new object right underneath it. 5 00:00:17,930 --> 00:00:21,350 Am I going to call this something like drink. 6 00:00:21,360 --> 00:00:26,830 No just a couple of videos ago we did some examples on drinks and we said that a drink had like a color 7 00:00:27,100 --> 00:00:30,160 and carbonated and some other thing like that. 8 00:00:30,340 --> 00:00:35,040 Let's try expressing a drink object right here with some of the same properties. 9 00:00:35,100 --> 00:00:44,120 Something like maybe give this thing a color that is brown and maybe carbonated carbonated and it'll 10 00:00:44,120 --> 00:00:50,030 be a Boolean true and then maybe it will also have like that sugar content and that's really supposed 11 00:00:50,030 --> 00:00:51,470 to be like number in grams. 12 00:00:51,470 --> 00:00:56,870 So like 40 grams of sugar and then I'm going to give this one more property I'm gonna give it a summary 13 00:00:56,870 --> 00:01:03,810 property summary is going to be a function anytime we call it it's going to return a String and so inside 14 00:01:03,810 --> 00:01:16,110 of here I'm going to return something like My drink is or how about has and then this dot Sugar grams 15 00:01:16,170 --> 00:01:18,160 of sugar and that's reasonable. 16 00:01:18,240 --> 00:01:23,230 Once again notice that I'm using back to X here to form up this string All right so here's what gets 17 00:01:23,230 --> 00:01:28,900 really interesting here is like the entire point of interfaces if you don't get this quite right away 18 00:01:28,900 --> 00:01:32,950 I'm going to show you a couple diagrams to really help you understand what's going on but here's what's 19 00:01:32,950 --> 00:01:34,140 going on. 20 00:01:34,150 --> 00:01:39,700 Notice how our old civic function has a summary function tied to it or some old Civic object has a summary 21 00:01:39,700 --> 00:01:45,250 function tied to it our drink object also has a summary function tied to it. 22 00:01:45,250 --> 00:01:51,610 These two objects right here represent very different things inside of our application but they both 23 00:01:51,610 --> 00:01:54,810 have a summary function that returns a string. 24 00:01:55,030 --> 00:02:03,010 That means that they are both considered to be reportable types so because they both have a property 25 00:02:03,010 --> 00:02:05,950 called summary that is a function that returns a string. 26 00:02:05,950 --> 00:02:14,980 This is of type reportable and this is of type reportable because they are both of type reportable we 27 00:02:14,980 --> 00:02:23,240 can use both old Civic and drink with the function we defined down here so I can call print summary 28 00:02:23,240 --> 00:02:31,310 with old Civic I can also call print summary with drink as well and it works equally well with both 29 00:02:31,370 --> 00:02:34,580 of these very different objects. 30 00:02:34,670 --> 00:02:35,920 So what's the big point here. 31 00:02:35,930 --> 00:02:43,370 The point is that we can use a single interface to describe the shape or the different properties of 32 00:02:43,370 --> 00:02:50,970 very different objects when we do so we can have those objects implement different properties or different 33 00:02:50,970 --> 00:02:57,570 functions and by doing so we can make these very different objects interact with different functions 34 00:02:57,660 --> 00:03:03,850 that we create like print summary right here so this encourages us to write somewhat generic looking 35 00:03:03,850 --> 00:03:04,300 functions. 36 00:03:04,300 --> 00:03:06,240 Notice how this is now print summary. 37 00:03:06,520 --> 00:03:11,740 Would it have made sense to have this be like print vehicle and then pass and drink to it. 38 00:03:11,740 --> 00:03:14,450 No I don't think that would have not made a lot of sense. 39 00:03:14,470 --> 00:03:20,350 So instead we decided to make a somewhat generic looking interface that described what we had to do 40 00:03:20,350 --> 00:03:22,600 in order to call this function right here. 41 00:03:22,610 --> 00:03:29,420 Gonna change that back to print summary by the way so in doing so we've now got a much more reusable 42 00:03:29,420 --> 00:03:31,730 function inside of our application. 43 00:03:31,730 --> 00:03:39,530 This function can be used with any type of object that satisfies the reportable interface and this feature. 44 00:03:39,540 --> 00:03:44,330 This right here is what is going to encourage us to write more reusable code with typescript. 45 00:03:44,340 --> 00:03:49,470 Now I know this is like a super basic example and it's very contrived but I just want this to be your 46 00:03:49,470 --> 00:03:55,170 first taste of how we're going to use interfaces in general now to make sure everything is super crystal 47 00:03:55,170 --> 00:03:55,710 clear here. 48 00:03:55,890 --> 00:03:59,940 Let's take a quick pause in the next video we're going to kind of reiterate what we did and what the 49 00:03:59,940 --> 00:04:02,130 entire point of this application was. 50 00:04:02,220 --> 00:04:05,820 We're going take a look at a couple of different diagrams to help you understand what's going on and 51 00:04:05,820 --> 00:04:10,380 we'll move on to our next subject where we're going to very quickly continue to see what the power of 52 00:04:10,380 --> 00:04:12,990 interfaces is inside of our applications. 53 00:04:12,990 --> 00:04:14,790 So quick pause and I'll see you in just a minute.