1 00:00:01,030 --> 00:00:02,250 Hi this is really hard. 2 00:00:02,260 --> 00:00:06,260 Once again welcome to the next video of this Carleen for now Mendel's. 3 00:00:06,280 --> 00:00:10,660 In this video we will talk about voter interfaces in case of Cartland. 4 00:00:11,020 --> 00:00:14,950 So let us first check out the practical example and then the Tuti. 5 00:00:14,950 --> 00:00:17,140 So here insert the intelligent ID. 6 00:00:17,140 --> 00:00:23,590 This is the example that we took in the previous video made about the abstraction in Gears of Cartland. 7 00:00:23,590 --> 00:00:32,140 Now suppose if I change this abstract open class to let's see interface and now the interface is not 8 00:00:32,140 --> 00:00:32,760 a class. 9 00:00:32,800 --> 00:00:34,260 Always remember this. 10 00:00:34,260 --> 00:00:40,180 It is something like a listener that you want some service such as on click of button. 11 00:00:40,180 --> 00:00:44,340 Something should happen on touch of a keyboard something should happen. 12 00:00:44,350 --> 00:00:48,210 So in that case the listener is actually the interface right. 13 00:00:48,280 --> 00:00:51,260 You want some short term or temporary service. 14 00:00:51,370 --> 00:00:57,230 So in that case we create the interface as for example in Android. 15 00:00:57,230 --> 00:00:59,570 Suppose someone click on a button. 16 00:00:59,600 --> 00:01:02,780 So on click of a button something should happen right. 17 00:01:02,780 --> 00:01:06,590 So we implement the on click method in case of Android. 18 00:01:06,590 --> 00:01:10,430 So that is the main purpose of interface in case of Cartland as well. 19 00:01:10,430 --> 00:01:16,790 So here let us change the name of interface Let's see might in Duffys listener. 20 00:01:17,060 --> 00:01:17,490 Right. 21 00:01:17,540 --> 00:01:21,330 And now here Vontae What do you define inside an interface. 22 00:01:21,440 --> 00:01:26,370 Is actually by default abstract in nature such as that. 23 00:01:26,450 --> 00:01:29,150 Let's say name string. 24 00:01:29,150 --> 00:01:34,210 Well it should not be name here because we are using the interface but it's a variable name so let it 25 00:01:34,240 --> 00:01:42,260 be named by default right now by default whatever you declare inside the interface is actually abstract 26 00:01:42,350 --> 00:01:48,620 and also open in nature because abstract variables and methods are by default open in nature that we 27 00:01:48,620 --> 00:01:50,600 saw in the previous review right. 28 00:01:50,840 --> 00:01:52,940 And this abstract is redundant. 29 00:01:52,970 --> 00:02:00,590 So we need to remove it as well and also abstract keywords and also abstract methods and also the variables 30 00:02:00,890 --> 00:02:04,960 should not contain some be FOID value like here. 31 00:02:05,150 --> 00:02:07,060 Let's say I mean name like this. 32 00:02:07,130 --> 00:02:11,690 So the abstract variables should not contain some initialized value. 33 00:02:11,780 --> 00:02:17,540 It should be a declaration like this so that it is removed as well because it is redundant. 34 00:02:17,840 --> 00:02:23,270 So here I have simply written a comment statement properties in gifts or interface or abstract Bideford 35 00:02:23,460 --> 00:02:24,130 right. 36 00:02:24,320 --> 00:02:26,760 And now suppose let us define a function. 37 00:02:26,810 --> 00:02:29,810 Let's see it or let's say on Glee. 38 00:02:30,080 --> 00:02:32,580 And here suppose if I define a body. 39 00:02:32,610 --> 00:02:39,950 Now if you define a body then this method is actually a normal function which is actually public in 40 00:02:39,950 --> 00:02:40,540 nature. 41 00:02:40,580 --> 00:02:47,420 But in this case it is not final in nature because in case of an Duffys nothing is final. 42 00:02:47,420 --> 00:02:49,880 Everything is open in nature. 43 00:02:49,970 --> 00:02:54,160 So this method is basically is by default open in nature. 44 00:02:54,160 --> 00:02:55,380 It is not final. 45 00:02:55,460 --> 00:02:59,340 So always remember in is in Duffys nothing is final. 46 00:02:59,390 --> 00:03:01,090 Everything is open in nature. 47 00:03:01,100 --> 00:03:03,190 So let me write a line for you. 48 00:03:03,560 --> 00:03:07,690 So the normal methods are public and open Bideford not final. 49 00:03:07,700 --> 00:03:09,200 Always remember. 50 00:03:09,410 --> 00:03:12,670 And now here this public and open keyword are redundant. 51 00:03:12,710 --> 00:03:16,990 So let us remove it and now let us define one more method. 52 00:03:17,030 --> 00:03:18,620 Let's see a function of. 53 00:03:18,830 --> 00:03:22,290 On page on pecial for which something should happen. 54 00:03:22,370 --> 00:03:29,870 Now here if I define here the body and declare here abstract then the compiler is again not happy because 55 00:03:29,870 --> 00:03:32,890 the abstract metrics cannot contain the body right. 56 00:03:33,020 --> 00:03:37,640 So here either I have to remove this or I have to remove this from here. 57 00:03:37,830 --> 00:03:42,150 But but I've tried this method to be abstract in nature right. 58 00:03:42,230 --> 00:03:48,430 So here they really do is I would simply remove the body now since it is abstract in nature. 59 00:03:48,500 --> 00:03:54,660 So you have the compulsorily or what I did inside the class that implements this interface. 60 00:03:54,950 --> 00:04:00,710 And now this was all about the properties inside the interface abstract methods and also the normal 61 00:04:00,790 --> 00:04:01,690 matters. 62 00:04:02,030 --> 00:04:04,850 And now suppose I have a class of Indian. 63 00:04:04,970 --> 00:04:09,320 Let's see let's remove it here and there doesn't modify the code. 64 00:04:09,410 --> 00:04:11,410 The class of bargain. 65 00:04:11,420 --> 00:04:17,120 Now suppose if I want to implement this in Duffys for this button so what I will do is I would simply 66 00:04:17,120 --> 00:04:23,520 use Blasberg then go alone then simply use my interface listener. 67 00:04:23,570 --> 00:04:25,750 Now this is actually the interface. 68 00:04:25,760 --> 00:04:32,510 Suppose you want to inherit some classic legacy person then for that you need to use the syntax isn't 69 00:04:32,570 --> 00:04:34,960 followed by the primary constructor. 70 00:04:35,240 --> 00:04:37,320 As we did in the previous videos. 71 00:04:37,520 --> 00:04:43,820 But if you want to implement the interface then you just have to specify galloon forward by interface 72 00:04:43,850 --> 00:04:44,470 name. 73 00:04:44,540 --> 00:04:47,160 There is no primary constructor here. 74 00:04:47,510 --> 00:04:51,320 Just because the interface cannot be instantiated. 75 00:04:51,320 --> 00:04:53,240 So here I've simply written the command line. 76 00:04:53,240 --> 00:04:55,920 You cannot create the instance of the abstract class. 77 00:04:56,090 --> 00:05:02,990 Let's make it in Duffys so the interface is similar to the abstract class cannot be instantiated. 78 00:05:03,000 --> 00:05:05,710 What I'm talking about is inside the main method. 79 00:05:05,720 --> 00:05:07,680 You simply cannot define that. 80 00:05:07,730 --> 00:05:14,420 Let's see may object equal to might in Duffys list. 81 00:05:14,470 --> 00:05:19,990 You can not do it because my interface is listen that can not contain a constructor as well. 82 00:05:19,990 --> 00:05:22,810 It is just an interface not a class. 83 00:05:22,810 --> 00:05:26,050 So always remember it is similar to Abchurch classes. 84 00:05:26,080 --> 00:05:29,990 The interface cannot be instantiated as remove it. 85 00:05:30,280 --> 00:05:33,970 And now here Legos move the person as well. 86 00:05:34,220 --> 00:05:37,950 So this is the syntax to get all the properties of this. 87 00:05:38,000 --> 00:05:41,100 Mike Duffy is listed there inside the class of button. 88 00:05:41,630 --> 00:05:46,240 And now let's call it my button as of now just to avoid any confusion. 89 00:05:46,310 --> 00:05:52,370 And now here it shows some error that if you are using the interface here then you must override this 90 00:05:52,430 --> 00:05:54,550 abstract method that is on edge. 91 00:05:54,650 --> 00:05:57,450 And also this abstract variable name. 92 00:05:57,500 --> 00:06:01,630 And now here this abstract abstract keyword is redundant. 93 00:06:02,560 --> 00:06:05,780 So again metrics in interface are abstracted by the. 94 00:06:05,890 --> 00:06:12,210 So to rectify this error we need to override this variable name and also function on stage because they 95 00:06:12,200 --> 00:06:13,410 are abstract in nature. 96 00:06:13,420 --> 00:06:16,540 So I will simply override. 97 00:06:17,150 --> 00:06:19,270 Let's see what I divide. 98 00:06:19,300 --> 00:06:24,930 Name other types of string and simply assign a default value with a dummy name. 99 00:06:25,860 --> 00:06:27,840 It is totally up to your choice. 100 00:06:27,840 --> 00:06:31,260 And now let us all read this abstract method as well. 101 00:06:31,290 --> 00:06:32,430 Function on page. 102 00:06:32,460 --> 00:06:37,310 So here I will simply use overdyed keyword SPEEs function. 103 00:06:37,540 --> 00:06:38,030 Let's see. 104 00:06:38,040 --> 00:06:45,280 On page so here the intelligent Id simply creates a placeholder to do for us. 105 00:06:45,360 --> 00:06:48,900 I simply define our own code right like this. 106 00:06:48,900 --> 00:06:51,460 Now coming to this point function on click. 107 00:06:51,480 --> 00:06:58,110 Now this function on click is not abstract in nature because it has a method and body so it is actually 108 00:06:58,110 --> 00:07:00,080 behaving like a normal method. 109 00:07:00,210 --> 00:07:03,400 So if you've warned it is totally your choice. 110 00:07:03,550 --> 00:07:06,300 You override that method or not. 111 00:07:06,360 --> 00:07:08,090 If you want you can also override it. 112 00:07:08,090 --> 00:07:10,380 It is totally up to your choice right. 113 00:07:10,710 --> 00:07:16,470 And if you want you can also call the support implementation of this method like Supernaut on click 114 00:07:16,470 --> 00:07:16,950 method. 115 00:07:16,950 --> 00:07:18,810 So as of now I don't want it. 116 00:07:18,990 --> 00:07:20,710 So that does remove it. 117 00:07:20,820 --> 00:07:23,130 You may or may not override this method. 118 00:07:23,260 --> 00:07:25,520 Right because this is a normal method. 119 00:07:25,590 --> 00:07:32,100 Now inside the main method what I'm going to do is simply create the instance of this class of my button 120 00:07:32,430 --> 00:07:38,330 because this my button is actually of the type of plus so began instantiated value. 121 00:07:38,450 --> 00:07:39,400 Let's see. 122 00:07:39,540 --> 00:07:42,790 And after this I would simply call my button and Dorte. 123 00:07:42,840 --> 00:07:45,900 Let's say on that great. 124 00:07:45,980 --> 00:07:47,340 So this was simply too good. 125 00:07:47,510 --> 00:07:55,920 This mentored president he had on pitch and also I will call my Verdon dark legacy on Glick. 126 00:07:56,180 --> 00:07:58,120 And this was simply very good this method. 127 00:07:58,150 --> 00:07:59,410 But as here. 128 00:07:59,570 --> 00:08:00,840 This on klick. 129 00:08:00,890 --> 00:08:02,650 Now let us define our record here. 130 00:08:02,720 --> 00:08:04,790 Let's see then. 131 00:08:05,110 --> 00:08:06,110 Martin was just. 132 00:08:06,170 --> 00:08:07,760 And he had Franklin as well. 133 00:08:07,770 --> 00:08:09,360 Burton was right. 134 00:08:09,620 --> 00:08:18,220 And I suppose if I had the court right now then these two statements is simply going to print the was 135 00:08:18,250 --> 00:08:22,770 just and also bartend was plugged in the output gunsel. 136 00:08:22,850 --> 00:08:28,400 So here in the output we get burdened was plagued button was dust and leaked like this. 137 00:08:28,640 --> 00:08:31,310 And now suppose inside the on click method. 138 00:08:31,310 --> 00:08:33,910 Suppose I have some print statement. 139 00:08:34,010 --> 00:08:39,470 Let's see Brant line on click interface boards right like this. 140 00:08:39,470 --> 00:08:42,800 So this is the opening line statement inside the on click method. 141 00:08:42,800 --> 00:08:45,950 Now suppose I want to print this statement as well. 142 00:08:46,100 --> 00:08:52,250 So far that what I really do is insert the limiter method inside of my Button class. 143 00:08:52,250 --> 00:08:59,180 What we do is I would simply use the super keyword superdog and I I'll simply call on click Metford. 144 00:08:59,280 --> 00:09:04,150 So this will simply Paragould the superclass method that is this one. 145 00:09:04,180 --> 00:09:10,680 Now remember this is not the class right but still we are inheriting all the properties of my in Duffys 146 00:09:10,710 --> 00:09:11,410 listener. 147 00:09:11,670 --> 00:09:13,510 Inside my button class. 148 00:09:13,680 --> 00:09:20,450 So they're just not called so in the output we get but then was just then only in Duffys scored but 149 00:09:20,500 --> 00:09:23,250 it was scored and then button was clicked. 150 00:09:23,430 --> 00:09:26,370 So this is how we call the superclass method. 151 00:09:26,420 --> 00:09:26,840 Right. 152 00:09:26,880 --> 00:09:29,930 Like we have done here superdog on click. 153 00:09:30,050 --> 00:09:33,940 Now if you want to and also remove this on click chord here. 154 00:09:33,980 --> 00:09:35,570 It will show no error. 155 00:09:36,050 --> 00:09:36,480 Right. 156 00:09:36,500 --> 00:09:43,370 But if you remove this on touch method then the compiler is not happy because this on this method is 157 00:09:43,370 --> 00:09:45,230 actually abstract in nature. 158 00:09:45,230 --> 00:09:46,720 So you need to override it. 159 00:09:46,740 --> 00:09:50,660 Anyhow here inside there did a plus. 160 00:09:50,870 --> 00:09:53,950 And now suppose I have one more in Duffys. 161 00:09:54,050 --> 00:09:56,170 So let us copy this in Duffys. 162 00:09:56,330 --> 00:10:01,150 My second in Duffys listener Ahlers lairds trimmed down the name. 163 00:10:01,160 --> 00:10:04,810 My second in Duffys right and now inside both the interface. 164 00:10:04,810 --> 00:10:06,620 Let's just modify our code. 165 00:10:06,770 --> 00:10:12,770 So here I will simply remove the variable name and also here name. 166 00:10:12,770 --> 00:10:18,860 And now I will simply convert this function on edge into the normal method. 167 00:10:19,040 --> 00:10:21,540 So I would simply define the body as. 168 00:10:21,890 --> 00:10:28,190 Let's see if Parentline aren't actually scored from my second interface on actual scored from my and 169 00:10:28,190 --> 00:10:29,200 in Duffys. 170 00:10:29,210 --> 00:10:31,150 Now similarly here I will. 171 00:10:31,220 --> 00:10:37,040 So here I have simply mortified my chord inside my industrious listener I am having on Dutch abstract 172 00:10:37,040 --> 00:10:39,490 matters without any body Nasima. 173 00:10:39,530 --> 00:10:42,680 I am having in inside my second interface. 174 00:10:42,710 --> 00:10:45,490 But it is not behaving as a normal method. 175 00:10:45,560 --> 00:10:47,940 It is no longer abstract method. 176 00:10:47,940 --> 00:10:52,470 Now this method and this method of yours truly seem right. 177 00:10:52,520 --> 00:10:57,020 So suppose I want to implement both the list inside my board and clothes. 178 00:10:57,170 --> 00:11:03,410 So what we do is this is our first listener and then I will simply give a coma and then implement my 179 00:11:03,410 --> 00:11:06,760 second interface like this right. 180 00:11:07,340 --> 00:11:08,280 And here it is. 181 00:11:08,320 --> 00:11:09,430 Will this statement. 182 00:11:09,650 --> 00:11:11,860 And now let just remove the chord as well. 183 00:11:11,950 --> 00:11:18,360 Here and now here it shows some error that you need to implement the abstract method so simply place 184 00:11:18,510 --> 00:11:23,280 it and go implement the members and English sure you two options. 185 00:11:23,280 --> 00:11:25,210 Mike Gardley in my interface listener. 186 00:11:25,230 --> 00:11:26,590 My second Duffys. 187 00:11:26,670 --> 00:11:32,760 We need to override this on Bush method which is actually abstract in nature so ask but our expectation 188 00:11:32,760 --> 00:11:34,650 that EDID should have been gone. 189 00:11:34,800 --> 00:11:38,140 But here if you notice the error is not gone. 190 00:11:38,460 --> 00:11:44,280 But as per the rule we have simply overridden this abstract method no rest of the methods are actually 191 00:11:44,280 --> 00:11:50,550 normal amateur's that should be optional to override such as on CLI mattered and also on the method 192 00:11:50,580 --> 00:11:52,040 of the second interface. 193 00:11:52,290 --> 00:11:59,940 But here we are using to interface now these two dollface have two amateur's on edge and on Glee and 194 00:11:59,940 --> 00:12:03,130 in one of the keys we have on Desch mentored as abstract. 195 00:12:03,270 --> 00:12:10,570 So we need to override this on page Metford complicity inside of my button plus but Varda bold on click 196 00:12:10,570 --> 00:12:11,170 mattered. 197 00:12:11,220 --> 00:12:14,970 This is normal my third here and this is again the normal method. 198 00:12:15,030 --> 00:12:16,100 No aspart at all. 199 00:12:16,110 --> 00:12:22,470 If there are two interface and there are two normal amateur's all of the same name inside the interface 200 00:12:22,560 --> 00:12:25,520 then you need to override that method as well. 201 00:12:25,530 --> 00:12:32,680 So here I have to simply press or enter and simply inherit the on click method here like this. 202 00:12:33,000 --> 00:12:35,010 So this rectifies our error. 203 00:12:35,320 --> 00:12:37,660 Right now supperless. 204 00:12:37,740 --> 00:12:46,260 I created the instance of my button like this and call my button on stage and my but and on click right 205 00:12:46,290 --> 00:12:51,680 now if I simply want to call this button dord on touch method then it will simply go into pretty good 206 00:12:52,080 --> 00:12:59,580 this method down the side inside the main button plus and if I want to trigger a superclass method then 207 00:12:59,850 --> 00:13:03,560 I would simply use superdog on page. 208 00:13:03,810 --> 00:13:05,850 So this statement is similar to good. 209 00:13:05,880 --> 00:13:13,110 The on page method here because this is the normal method and this is the abstract method without any 210 00:13:13,110 --> 00:13:13,540 body. 211 00:13:13,560 --> 00:13:19,770 So there is no point of this method being called because this method don't have any code. 212 00:13:19,860 --> 00:13:22,110 And here I have some code right. 213 00:13:22,170 --> 00:13:28,320 So this statement will simply trigger the superclass on Bash method of my second interface that has 214 00:13:28,320 --> 00:13:29,760 some Vardi. 215 00:13:29,910 --> 00:13:34,120 And now suppose this statement is executed Mayberg and or unclick. 216 00:13:34,230 --> 00:13:39,670 So this will simply trigger this local method off on leg press and inside my button plus. 217 00:13:39,810 --> 00:13:44,760 So here if I call Lexie's soup it dawned on click. 218 00:13:44,940 --> 00:13:49,890 So what will happen it will simply show some error because the compiler will be confused. 219 00:13:49,920 --> 00:13:56,880 That are superdog on click Metford is actually present in boot that case that is in this interface and 220 00:13:56,880 --> 00:14:02,080 also inserted this in Duffys so it gets simply confused which meant to call. 221 00:14:02,180 --> 00:14:05,970 Right so in that case we have a solution here. 222 00:14:06,000 --> 00:14:07,960 We can simply define super. 223 00:14:08,160 --> 00:14:12,460 I simply pass the name of the Duffys super. 224 00:14:12,550 --> 00:14:19,640 My interface listener got on click and again if you want to call this Mazak an interface on click Metford 225 00:14:20,310 --> 00:14:28,420 then you can simply call super and simply pass the name of my second interface Dorte on click. 226 00:14:28,690 --> 00:14:34,920 Right so these two statements are simply going to trigger the respective on click methods present inside 227 00:14:34,920 --> 00:14:35,850 the interface. 228 00:14:35,850 --> 00:14:37,810 Here and here like this. 229 00:14:38,790 --> 00:14:44,400 So always remember this while you are using there to interface and if the interface contains the same 230 00:14:44,440 --> 00:14:45,120 third name. 231 00:14:45,210 --> 00:14:47,650 So how to handle that situation. 232 00:14:47,670 --> 00:14:50,290 I just showed you in this example. 233 00:14:50,610 --> 00:14:53,300 So this was all about the practical example. 234 00:14:53,370 --> 00:14:55,900 No need to jump back to the tutor Dickel example. 235 00:14:56,130 --> 00:15:01,430 So the interface can contain both normal methods and also abstract methods. 236 00:15:01,440 --> 00:15:03,190 So always remember this. 237 00:15:03,270 --> 00:15:10,050 It can contain normal as well as abstract methods but in gesso property they can contain only abstract 238 00:15:10,050 --> 00:15:15,990 property that is you cannot initialize any variable inside the interface. 239 00:15:16,260 --> 00:15:17,470 Novels are going forward. 240 00:15:17,550 --> 00:15:19,480 The indices are not a class. 241 00:15:19,500 --> 00:15:23,460 So do remember this and now similar to the abstract class. 242 00:15:23,490 --> 00:15:28,580 You can not create the instance of the interface because the interface is not a class. 243 00:15:28,590 --> 00:15:35,090 It is something different thing that only provides a short term sort of his such as a button click on 244 00:15:35,110 --> 00:15:39,280 touch when you check the checkbox when you try to open their dialog box. 245 00:15:39,300 --> 00:15:40,440 And something like that. 246 00:15:40,500 --> 00:15:44,570 So it simply provides a short them service right there in Duffys. 247 00:15:44,610 --> 00:15:47,400 So this was all about the interface in case of Cartland.