In the last video we reflected 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 object called old Civic on a define another new object right underneath it.
Am I going to call this something like drink.
No 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 the same properties.
Something like maybe give this thing a color that is brown and maybe carbonated carbonated and it'll
be a Boolean true and then maybe it will also have like that sugar content and that's really supposed
to be like number in grams.
So like 40 grams of sugar and then I'm going to give this one more property I'm gonna give it a summary
property summary is going to be a function anytime 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 dot Sugar grams
of sugar and that's reasonable.
Once again notice that I'm using back to X here to form up this string All right so here's what gets
really interesting here is like the entire point of interfaces if you don't get this quite right away
I'm going to show you a couple 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 print summary
with old Civic I can also call print 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 print summary.
Would it have made sense to have this be like print vehicle and then pass and 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.
Gonna change that back to print summary by the way so in doing so we've now got a much more reusable
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 of this application was.
We're going 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.