Hi everyone.
Welcome back.
In this lecture we are going to learn about how do you create a sealed interface and how do we plug
that in into our object oriented design.
So in this case we have this car class.
Now what we are thinking is that most of the cars nowadays are really smart.
So what we need is a smart media player using which you can connect your phone, and then you can play
music, and then you can actually talk to your friends and family through the smart media player.
So what I'm going to do, I'm going to create an interface named Smart Media Player.
And that's going to be a sealed interface okay.
So right click over here.
In this case select the interface over here.
And then I'm going to name this one as Smart Media player.
So this is kind of an interface that can be plugged into any type of vehicle actually.
But in this case I want to implement the smart media player in the car class.
Okay.
Let's go ahead and create this interface.
So I'm going to make this interface sealed because sealed keyword is allowed to be used in the interface
or class.
So far we have seen using sealed with the classes.
Now we are exploring the usage of sealed with the interface.
So in this case I'm going to have this getting implemented in the car class.
So in this case permits car okay.
So I'm going to define a function named connect phone okay.
So any class that implements this interface will have this function available.
So in this case connect phone we can have some additional functions like play music make phone calls
and all those things.
But I'm going to keep this example really simple.
So in this case let's go to the permit class.
So in the permit class we're going to do the implements smart media player.
Now let's look into the compilation issue.
So the compilation issue I believe this needs to come after the instance.
And permits should be the last declaration in this whole thing.
Let's go ahead and add that.
And then let's go ahead and implement the method which is the connect form.
phone.
So in this case we have the connect function which is a connect phone function implemented over here.
Okay.
So I'm just going to print over here.
So it can be like phone connected.
And we can have some additional functionalities added to it.
So this is how you implement a seal interface into your class hierarchy.
So this is very similar to the interface that we normally create.
But by making it sealed you are making sure this particular interface gets implemented on the class
that you defined after the permits keyword.
So I hope the explanation is clear.
If you have any kind of questions or clarifications, you are welcome to write it in Q&A.
I'll be happy to help.
So this wraps up the usage of creating a seal interface.
And how do you incorporate that in your hierarchy?
One key thing to call out is that the permits should be the last block in your whole class definition.
Okay, this marks the end of this lecture.
Thank you for watching.