WEBVTT

00:00.050 --> 00:00.710
Hi everyone.

00:00.710 --> 00:01.310
Welcome back.

00:01.310 --> 00:06.350
In this lecture we are going to learn about how do you create a sealed interface and how do we plug

00:06.350 --> 00:08.930
that in into our object oriented design.

00:08.930 --> 00:11.090
So in this case we have this car class.

00:11.090 --> 00:15.470
Now what we are thinking is that most of the cars nowadays are really smart.

00:15.470 --> 00:21.800
So what we need is a smart media player using which you can connect your phone, and then you can play

00:21.800 --> 00:26.930
music, and then you can actually talk to your friends and family through the smart media player.

00:26.930 --> 00:31.640
So what I'm going to do, I'm going to create an interface named Smart Media Player.

00:31.640 --> 00:34.820
And that's going to be a sealed interface okay.

00:34.850 --> 00:36.170
So right click over here.

00:36.200 --> 00:39.740
In this case select the interface over here.

00:39.740 --> 00:43.370
And then I'm going to name this one as Smart Media player.

00:43.370 --> 00:48.170
So this is kind of an interface that can be plugged into any type of vehicle actually.

00:48.170 --> 00:52.820
But in this case I want to implement the smart media player in the car class.

00:52.850 --> 00:53.120
Okay.

00:53.120 --> 00:54.560
Let's go ahead and create this interface.

00:54.560 --> 01:02.520
So I'm going to make this interface sealed because sealed keyword is allowed to be used in the interface

01:02.550 --> 01:03.390
or class.

01:03.390 --> 01:06.840
So far we have seen using sealed with the classes.

01:06.870 --> 01:10.320
Now we are exploring the usage of sealed with the interface.

01:10.320 --> 01:15.240
So in this case I'm going to have this getting implemented in the car class.

01:15.240 --> 01:17.880
So in this case permits car okay.

01:17.910 --> 01:21.390
So I'm going to define a function named connect phone okay.

01:21.420 --> 01:26.070
So any class that implements this interface will have this function available.

01:26.070 --> 01:32.490
So in this case connect phone we can have some additional functions like play music make phone calls

01:32.490 --> 01:33.300
and all those things.

01:33.300 --> 01:35.610
But I'm going to keep this example really simple.

01:35.610 --> 01:37.350
So in this case let's go to the permit class.

01:37.350 --> 01:42.120
So in the permit class we're going to do the implements smart media player.

01:42.150 --> 01:44.130
Now let's look into the compilation issue.

01:44.130 --> 01:48.330
So the compilation issue I believe this needs to come after the instance.

01:48.330 --> 01:51.900
And permits should be the last declaration in this whole thing.

01:51.930 --> 01:52.980
Let's go ahead and add that.

01:52.980 --> 01:56.730
And then let's go ahead and implement the method which is the connect form.

01:56.730 --> 01:56.750
phone.

01:56.750 --> 02:02.240
So in this case we have the connect function which is a connect phone function implemented over here.

02:02.450 --> 02:02.690
Okay.

02:02.720 --> 02:04.340
So I'm just going to print over here.

02:04.340 --> 02:07.400
So it can be like phone connected.

02:10.280 --> 02:13.880
And we can have some additional functionalities added to it.

02:13.880 --> 02:19.160
So this is how you implement a seal interface into your class hierarchy.

02:19.160 --> 02:22.700
So this is very similar to the interface that we normally create.

02:22.700 --> 02:29.210
But by making it sealed you are making sure this particular interface gets implemented on the class

02:29.210 --> 02:31.820
that you defined after the permits keyword.

02:31.820 --> 02:34.040
So I hope the explanation is clear.

02:34.040 --> 02:38.780
If you have any kind of questions or clarifications, you are welcome to write it in Q&amp;A.

02:38.810 --> 02:40.220
I'll be happy to help.

02:40.220 --> 02:43.880
So this wraps up the usage of creating a seal interface.

02:43.880 --> 02:46.370
And how do you incorporate that in your hierarchy?

02:46.400 --> 02:52.610
One key thing to call out is that the permits should be the last block in your whole class definition.

02:52.640 --> 02:54.500
Okay, this marks the end of this lecture.

02:54.500 --> 02:55.550
Thank you for watching.
