1 00:00:00,300 --> 00:00:06,450 So will come back again in this list and we're going to talk about protocols so protocols as the name 2 00:00:06,450 --> 00:00:15,200 implies are essentially a set of instructions and a class or a structure on ENM will adopt to that protocol 3 00:00:15,240 --> 00:00:21,830 meaning whatever rules are there in the protocol that class or data structure that Inform should follow. 4 00:00:21,990 --> 00:00:23,640 So why is this useful for us. 5 00:00:23,640 --> 00:00:29,820 It is useful for us in a situation where we have different classes that we want all of them to conform 6 00:00:29,820 --> 00:00:31,740 to a certain set of things. 7 00:00:31,740 --> 00:00:37,920 For instance they all have showed a certain number of primitives or they all should implement a certain 8 00:00:37,920 --> 00:00:39,060 function. 9 00:00:39,060 --> 00:00:44,500 Now what is important to understand about protocols is that they don't actually contain any logic. 10 00:00:44,580 --> 00:00:50,530 They just have the declaration of the methods or attributes they don't understand what is going to happen 11 00:00:50,530 --> 00:00:51,100 to be taught. 12 00:00:51,090 --> 00:00:53,420 And they don't have the implementation of it. 13 00:00:53,460 --> 00:01:00,240 So in Turin you could have protocols that are adopted by different classes but each class does its own 14 00:01:00,240 --> 00:01:01,570 thing on their mettle. 15 00:01:01,710 --> 00:01:08,350 So the school head into a school and going I start a new project I'm going to make it of the types with 16 00:01:08,450 --> 00:01:17,850 and is going to be protocol protocols with particular protocols the right protocol swift 17 00:01:20,510 --> 00:01:21,490 animal protocols. 18 00:01:21,500 --> 00:01:30,200 If I'm going to do this I'm going to say I have one protocol and that protocol is going to be let's 19 00:01:30,200 --> 00:01:32,780 call our protocol admissible. 20 00:01:33,260 --> 00:01:33,620 All right. 21 00:01:33,620 --> 00:01:41,310 It means anyone who conforms to this is acceptable or is admissible not nine. 22 00:01:41,400 --> 00:01:47,270 And we are working on that same application that we have discussed multiple times which is about a real 23 00:01:47,270 --> 00:01:49,840 estate property listing application. 24 00:01:49,970 --> 00:01:53,390 So in the application we have a clause for property. 25 00:01:53,660 --> 00:01:55,210 We have a class for Agent. 26 00:01:55,210 --> 00:02:00,470 These are the people who list the different properties and we have in class for the user. 27 00:02:00,470 --> 00:02:03,230 These other people who browse between properties. 28 00:02:03,230 --> 00:02:06,410 Now all of these they share some attributes. 29 00:02:06,500 --> 00:02:12,870 Let's say they all have a status that is called active whether they are currently active or not. 30 00:02:12,880 --> 00:02:16,060 It is the property that is currently active or not an agent does. 31 00:02:16,070 --> 00:02:18,560 I will not use it as I will not. 32 00:02:18,560 --> 00:02:19,960 They will have a rating. 33 00:02:20,010 --> 00:02:25,160 So each of them at any given point has a rating user agent or property. 34 00:02:25,160 --> 00:02:28,310 Also they all have a function called rates. 35 00:02:28,320 --> 00:02:32,920 It's of course they all have a you idea they have a unique ID. 36 00:02:32,960 --> 00:02:34,420 So what they want to do is this. 37 00:02:34,450 --> 00:02:41,750 I want to make sure that this protocol includes all of these and every class that conforms to this protocol 38 00:02:41,750 --> 00:02:46,700 makes sure those classes have to incorporate these items in them. 39 00:02:46,820 --> 00:02:53,090 So the first thing is I'm going to say there is a valuable called active that is of the type Boolean 40 00:02:53,540 --> 00:02:57,220 and this is something that we can both get unset. 41 00:02:57,270 --> 00:03:03,230 This is essentially like that thing we had the read only or read the right and we'll get to see more 42 00:03:03,230 --> 00:03:09,320 of these things soon enough that there are items that we can or attributes that we can only read them 43 00:03:09,380 --> 00:03:12,700 or the ones that we can both read and write into them. 44 00:03:12,740 --> 00:03:17,910 So once we have that I have another value does of it is called you. 45 00:03:18,120 --> 00:03:19,920 ID is a string. 46 00:03:19,940 --> 00:03:24,860 And again it is a set and get we can both set and get them. 47 00:03:24,860 --> 00:03:31,480 We have something else called larger rate which is a float and this event is only. 48 00:03:31,480 --> 00:03:38,600 Yet we can not set it simply because rating should be calculated based on some some sort of algorithm 49 00:03:38,600 --> 00:03:44,570 something that calculates the value and tells us what the current weight rating is 4.2 or something 50 00:03:44,570 --> 00:03:45,650 to that effect. 51 00:03:45,710 --> 00:03:53,700 And then finally we have a function call rate it and this function doesn't have any body weight. 52 00:03:53,930 --> 00:04:01,550 Or maybe it has only one argument to rate it with import rate of a floater value and then like I said 53 00:04:01,610 --> 00:04:03,680 it doesn't have any logic. 54 00:04:03,680 --> 00:04:06,480 It just says this declaration exists. 55 00:04:06,530 --> 00:04:09,080 And that's the goal of having a protocol. 56 00:04:09,380 --> 00:04:13,100 Now let's go ahead and make our archery classes. 57 00:04:13,100 --> 00:04:14,540 I'm going to say I have a class. 58 00:04:14,540 --> 00:04:21,300 This course is going to be called property and it does conform to admissible. 59 00:04:21,500 --> 00:04:26,630 And the moment we do this we should see some sort of error given to us by the compiler OFX code. 60 00:04:26,630 --> 00:04:32,220 It's saying that it doesn't completely conform to this protocol you are missing some stuff. 61 00:04:32,240 --> 00:04:37,940 Would you like to add them I'm going to say yes and then it says well if you want to add them you have 62 00:04:37,940 --> 00:04:43,610 to make sure you have the activity you have the you ID you have the rating and you have this function 63 00:04:44,280 --> 00:04:47,870 and now that we have those we have to actually initialize this. 64 00:04:47,870 --> 00:04:52,920 We can just leave them there because the class is going to say well I know you have these three but 65 00:04:52,930 --> 00:04:55,310 when are you going are going to initialize them. 66 00:04:55,440 --> 00:05:01,390 I'm going to say in that and in the in it I'm going to say I haven't been active. 67 00:05:01,700 --> 00:05:02,820 That is half the time. 68 00:05:02,950 --> 00:05:09,590 And so when the initialise something is it active or not and then that to you idea and rate they have 69 00:05:09,590 --> 00:05:11,790 to be calculated at some other time. 70 00:05:11,810 --> 00:05:16,530 In that case active becomes Impe active. 71 00:05:16,940 --> 00:05:24,920 And then I'm going to say you ID for instance becomes you you ID dot you you idea string. 72 00:05:25,260 --> 00:05:29,550 And then the rate at the very very beginning we set it to be zero. 73 00:05:31,430 --> 00:05:40,930 And that whole my property class has conformed to the admissible protocol or Essentially it's been adapted 74 00:05:40,930 --> 00:05:44,480 to that and that's the same thing we have to do with everybody else. 75 00:05:44,500 --> 00:05:49,920 If we have a class called Agent we have to do that if you have a classical user you have to that. 76 00:05:50,020 --> 00:05:56,170 And of course each of these classes will have their own thing applying a protocol is very similar to 77 00:05:56,230 --> 00:06:01,160 writing three classes are making sure that each of the three classes have these. 78 00:06:01,360 --> 00:06:07,510 Even if it didn't have the protocol and we didn't have that this class would work on its own nothing 79 00:06:07,510 --> 00:06:13,410 is wrong with it having the political makes sure that we apply the same rule to everyone. 80 00:06:13,600 --> 00:06:16,020 I'm one of the places that we use protocols. 81 00:06:16,070 --> 00:06:19,430 Is isn't something that we call it delegation pattern. 82 00:06:19,630 --> 00:06:25,000 And that's something that you're going to see in an upcoming lesson which is a very very important part 83 00:06:25,000 --> 00:06:26,830 of you know Iowa's development. 84 00:06:27,010 --> 00:06:29,910 But for now Protocols are a set of rules. 85 00:06:29,920 --> 00:06:37,120 They have their instructions no logic they have the attributes and they know where they are get upset 86 00:06:37,150 --> 00:06:38,470 or only get. 87 00:06:38,620 --> 00:06:46,000 And then when we adopt them by any class it means all of those things in that protocol must exist in 88 00:06:46,000 --> 00:06:46,670 here. 89 00:06:47,140 --> 00:06:50,810 That function has to be there and those because they have to be there. 90 00:06:50,950 --> 00:06:52,740 And with that let's move on to our.