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