1 00:00:00,890 --> 00:00:04,610 In this video I want to show you a couple different diagrams to help you really understand what is going 2 00:00:04,610 --> 00:00:08,510 on inside this file and really understand what the goal of the interface is right here. 3 00:00:08,510 --> 00:00:09,370 So let's get to it. 4 00:00:10,480 --> 00:00:10,970 All right. 5 00:00:10,990 --> 00:00:14,650 On the left hand side at the very bottom we've got that print summary function that we just put together 6 00:00:15,750 --> 00:00:21,480 we can kind of think of that interface that we are using to annotate the argument to that function as 7 00:00:21,480 --> 00:00:24,150 being like a gatekeeper of sorts. 8 00:00:24,150 --> 00:00:29,070 In other words if we ever have any value inside of application like say old Civic or drink over here 9 00:00:29,480 --> 00:00:34,680 and we want to use these values with a print summary function we have to make sure that those values 10 00:00:34,770 --> 00:00:37,990 implement the reportable interface. 11 00:00:38,010 --> 00:00:42,690 In other words these two values have to have a summary function that returns a string. 12 00:00:42,900 --> 00:00:49,520 If they don't then they can not be used with print summary this mechanic right here of using an interface 13 00:00:49,520 --> 00:00:55,130 for gatekeeping is going to be one of the prime ways that we get some amount of code reuse inside of 14 00:00:55,130 --> 00:01:00,650 TypeScript and you're going to see the strategy used over and over in every application we put together 15 00:01:00,650 --> 00:01:06,710 in this course so the general strategy that we're going to use for code reuse in typescript is to create 16 00:01:06,710 --> 00:01:13,590 functions that accept arguments that are typed with interfaces so all the different functions we're 17 00:01:13,590 --> 00:01:17,950 going to create are going to accept interfaces as much as possible. 18 00:01:18,000 --> 00:01:22,830 Obviously not every last function we ever put together is always going to require an interface type 19 00:01:22,830 --> 00:01:23,510 argument. 20 00:01:23,550 --> 00:01:28,800 Sometimes we're going to have something it takes a string or a boolean or maybe a plain object in some 21 00:01:29,160 --> 00:01:30,390 far off cases. 22 00:01:30,600 --> 00:01:35,520 But in general we're going to try to create functions that accept arguments that are typed with interfaces 23 00:01:36,450 --> 00:01:42,630 and then in order to call those functions we're going to make sure that we have objects or classes that 24 00:01:42,630 --> 00:01:49,690 can decide to implement that interface so it's essentially this same scenario right over here we created 25 00:01:49,690 --> 00:01:56,080 a function that takes an interface type as an argument so other values inside of application can opt 26 00:01:56,100 --> 00:02:02,450 into satisfying or implementing that interface to work with that function this diagram that you're seeing 27 00:02:02,450 --> 00:02:07,550 right here we can kind of generalize into something like this so we can imagine some like arbitrary 28 00:02:07,550 --> 00:02:12,140 interface over here that's going to govern access to some function and if we want to work with this 29 00:02:12,140 --> 00:02:16,790 function any other object must implement that interface. 30 00:02:16,790 --> 00:02:21,620 So we're going to see this exact diagram right here in many other applications we work on and every 31 00:02:21,620 --> 00:02:26,030 single time it's gonna have the exact same meaning we're going to talk about how we've got some function 32 00:02:26,270 --> 00:02:31,940 and in order to call it we might we must have some values that implement the given interface that's 33 00:02:31,940 --> 00:02:34,850 acting as the gatekeeper All right. 34 00:02:34,880 --> 00:02:39,140 So at this point I'm sure this is still a little bit confusing but like I said earlier the good news 35 00:02:39,140 --> 00:02:44,780 is that the entire course like every application we put together is going to be focusing 100 percent 36 00:02:44,840 --> 00:02:46,110 on this mechanic. 37 00:02:46,280 --> 00:02:51,440 We're gonna be focusing on how to define different interfaces to restrict access to different functions 38 00:02:52,010 --> 00:02:57,640 and then decide how to implement those different interfaces in different objects so we're going to create. 39 00:02:57,670 --> 00:03:01,880 So the real code reuse we're going to get here is making essentially this function right here really 40 00:03:01,910 --> 00:03:02,960 reusable. 41 00:03:02,960 --> 00:03:07,590 As long as a value implements that interface it can work with this function. 42 00:03:07,610 --> 00:03:07,820 All right. 43 00:03:07,830 --> 00:03:09,190 So let's take a quick pause right here. 44 00:03:09,190 --> 00:03:11,240 We're gonna move on to our next topic in the next video.