In the last video, we refactored our interface to have a little bit more generic name.
We did the same thing with our function down here.
So now I want to do something kind of interesting inside this file.
Right now, we've got a project called Old Civic.
I want to define another new object right underneath it.
And I'm going to call this something like drink.
Remember just a couple of videos ago, we did some examples on drinks and we said that a drink had like
a color and carbonated and some other thing like that.
Let's try expressing a drink object right here with some of those same properties.
So I'm going to like maybe give this thing a color that is brown and maybe carbonated.
Carbonated.
And that'll be a boolean, true, and then maybe it will also have like that sugar content, and that's
really supposed to be like no Ingrams.
So like 40 grams of sugar.
And then I'm going to give this one more property, I'm going to give it a summary, property summary
is going to be a function any time we call it.
It's going to return a string.
And so inside of here, I'm going to return something like my drink is.
Or how about has and then this diet sugar.
Grams of sugar, that's reasonable, once again, notice that I'm using tactics here to form up the
string.
All right, so here's what gets really interesting, here's like the entire point of interfaces, if
you don't get this quite right away, I'm going to show you a couple of diagrams to really help you
understand what's going on.
But here's what's going on.
Notice how our old civic function has a summary function tied to it or some old civic object has a summary
function tied to it.
Our drink object also has a summary function tied to it.
These two objects right here represent very different things inside of our application, but they both
have a summary function that returns a string.
That means that they are both considered to be reportable types.
So because they both have a property called summary, that is a function that returns a string, this
is of type reportable and this is of type reportable.
Because they are both of type reportable, we can use both old civic and drink with the function we
defined down here.
So I can call Prince Summary with old Civic, I can also call Prince Summary with drink as well.
And it works equally well with both of these very different objects.
So what's the big point here?
The point is that we can use a single interface to describe the shape or the different properties of
very different objects.
When we do so, we can have those objects implement different properties or different functions, and
by doing so we can make these very different objects interact with different functions that we create,
like print summary right here.
So this encourages us to write somewhat generic looking functions.
Notice how this is now a print summary.
Would it have made sense to have this be like print vehicle and then pass in drink to it?
No, I don't think that would have not made a lot of sense.
So instead, we decided to make a somewhat generic looking interface that described what we had to do
in order to call this function right here.
I'm going to change that.
Back to print summary, by the way.
So in doing so, we've now got a much more reuseable function inside of our application, this function
can be used with any type of object that satisfies the reportable interface.
And this feature, this right here, is what is going to encourage us to write more reusable code with
TypeScript.
Now, I know this is like a super basic example and it's very contrived, but I just want this to be
your first taste of how we're going to use interfaces in general.
Now, to make sure everything is super crystal clear here, let's take a quick pause in the next video,
we're going to kind of reiterate what we did and what the entire point on this application was.
We're going to take a look at a couple of different diagrams to help you understand what's going on.
And we'll move on to our next subject, where we're going to very quickly continue to see what the power
of interfaces is inside of our applications.
So quick pause and I'll see you in just a minute.