1 00:00:00,870 --> 00:00:07,330 So the first thing we need to understand in here is the concept of or pick what is or the opiate stands 2 00:00:07,330 --> 00:00:09,700 for object oriented programming. 3 00:00:09,790 --> 00:00:14,200 And it is something that you have been using throughout the previous lessons but we never got the chance 4 00:00:14,200 --> 00:00:19,380 to talk about it now or be cannot really be explained on its own. 5 00:00:19,390 --> 00:00:26,050 I'd rather if I talked about in contrast and comparison to other programming paradigms to the best of 6 00:00:26,050 --> 00:00:29,960 my knowledge there is crankily four different programming paradigms. 7 00:00:30,010 --> 00:00:36,730 They are all P functional imperative and logical now functional programming essentially means program 8 00:00:36,760 --> 00:00:43,600 is a series of mathematical formulas that they work next which other imperative means program is a series 9 00:00:43,600 --> 00:00:49,300 of instructions that each instruction does something and they follow the program and then that is the 10 00:00:49,300 --> 00:00:54,600 logical which is essentially modeling information on the relationship between them all. 11 00:00:54,620 --> 00:01:01,390 PS In your concept object oriented programming essentially means that you have instructions that they 12 00:01:01,390 --> 00:01:08,080 build something from those instructions you build the things that you want and you have the relationship 13 00:01:08,080 --> 00:01:08,940 between them. 14 00:01:09,130 --> 00:01:16,390 So an instruction that we call a class knows how to build a car and then from there you make your first 15 00:01:16,390 --> 00:01:22,890 car and then your second car Angleterre car and each car has a set of attributes and a set of methods. 16 00:01:22,930 --> 00:01:29,320 So each car has things such as the color of the car or the maximum the speed of the car and then it 17 00:01:29,320 --> 00:01:34,440 has some functions such as drive change year stop. 18 00:01:34,450 --> 00:01:40,480 Now the advantage of all p is that every object that is made of a class is independent from the other 19 00:01:40,480 --> 00:01:46,090 instances of that class and they can all interact with each other or with other objects. 20 00:01:46,120 --> 00:01:51,200 To put these concepts in a better context lets go ahead and have a look at some images. 21 00:01:51,400 --> 00:01:53,570 I highlighted some images in here. 22 00:01:53,830 --> 00:01:57,780 So the first example of all IP is a class of a car. 23 00:01:58,060 --> 00:02:05,620 So it might classify a car has some method such as refuelled or get fuel or get set speed or get speed 24 00:02:05,980 --> 00:02:08,940 or drive and it has some attributes. 25 00:02:09,010 --> 00:02:13,210 The current amount of fuel the maximum speed this car can go. 26 00:02:13,330 --> 00:02:19,370 And as you can imagine this class is what we call a blueprint for building different cars. 27 00:02:19,510 --> 00:02:24,270 So from this class I can make my object one of which is a class that does something. 28 00:02:24,280 --> 00:02:29,720 Now if you're trying to relate this to the things that we have seen so far this is unnecessary. 29 00:02:29,860 --> 00:02:31,880 It knows how to make a string. 30 00:02:31,990 --> 00:02:35,450 It knows how to keep some text values in it. 31 00:02:35,680 --> 00:02:39,230 And then you can make as many of those as you want. 32 00:02:39,400 --> 00:02:45,520 Eating is essentially the same way it's an endless array it's a class of N.S. mutable dictionary so 33 00:02:45,520 --> 00:02:50,440 on and so forth they each have some attributes and they each have some methods. 34 00:02:50,530 --> 00:02:52,770 My next example is this one. 35 00:02:52,840 --> 00:02:59,530 There is a class building that knows how to produce different buildings and then from that if we make 36 00:02:59,530 --> 00:03:05,710 one empire state that's an instance of a building or my other class is dog. 37 00:03:05,710 --> 00:03:11,550 And from the dog class we make this particular dog called Lassie which she said somewhat seriously then 38 00:03:11,560 --> 00:03:15,960 of course by setting different attributes on different instances of different objects. 39 00:03:16,090 --> 00:03:21,520 We obviously make different models we have different things that they interact with each other just 40 00:03:21,520 --> 00:03:27,730 like you know if you are making our users in some of the previous lessons then for each user We had 41 00:03:27,730 --> 00:03:32,650 a different set of information different name two different photos so on and so forth. 42 00:03:32,760 --> 00:03:38,770 And obviously my last example is a computer that from a computer class we can make this particular computer 43 00:03:39,050 --> 00:03:44,530 that does particularly in our settings and actually it's not all play has a lot of different jargon 44 00:03:44,530 --> 00:03:45,000 in it. 45 00:03:45,070 --> 00:03:46,540 We have to talk about classes. 46 00:03:46,540 --> 00:03:52,680 We have to talk about that abstraction encapsulation inheritance information hiding polymorphism and 47 00:03:52,680 --> 00:03:55,490 there's some other stuff that we'll talk about as well. 48 00:03:55,510 --> 00:03:58,910 So we have a long way to go to understand every bit of this. 49 00:03:58,990 --> 00:04:04,810 One good news is we have seen most of this in practice so far we have used classes. 50 00:04:04,810 --> 00:04:06,580 We have made objects of them. 51 00:04:06,720 --> 00:04:11,270 If you haven't seen inheritance you then know its name but we have kind of seen it. 52 00:04:11,440 --> 00:04:15,620 Now before I close this lesson I move on to actual programming in Axford. 53 00:04:15,700 --> 00:04:21,580 I want to show you one more example of classes and objects. 54 00:04:21,580 --> 00:04:25,120 So I have developed this very crude you know demonstration. 55 00:04:25,300 --> 00:04:31,660 So I imagine this example is for real life situation is for a human that needs to speak French from 56 00:04:31,660 --> 00:04:36,000 time to time needs cooking and also needs access to a car. 57 00:04:36,010 --> 00:04:37,330 Now the way it works is this. 58 00:04:37,360 --> 00:04:42,820 Every once in awhile I get a phone call and somebody is talking French so I need someone to translate 59 00:04:42,820 --> 00:04:49,380 that for me or a neat way of translating French because I don't speak French or every once in a while 60 00:04:49,380 --> 00:04:53,620 don't need to be cooking something and every once in a while I need transportation so I need access 61 00:04:53,620 --> 00:04:54,440 to a car. 62 00:04:54,640 --> 00:05:00,910 So if you've really not impressive programming paradigm what you would do is when they get a free talking 63 00:05:00,910 --> 00:05:06,470 guy over the phone you would write a program that translates French to say English. 64 00:05:06,580 --> 00:05:12,040 So you would write the entire set of instructions that does something for us then we needed to cook 65 00:05:12,040 --> 00:05:17,290 something that would write the entire set of instructions that does the cooking and so on the same thing 66 00:05:17,290 --> 00:05:22,680 for transportation you know an opium mother we do things a little bit differently in all people. 67 00:05:22,900 --> 00:05:29,710 When we have a need for someone that speaks French we get an object from French that we call it French 68 00:05:29,710 --> 00:05:30,890 translator one. 69 00:05:31,030 --> 00:05:35,760 So we get an instance of that class that is about translating French. 70 00:05:35,890 --> 00:05:41,800 And then if later on I need to cook something I get my cook the first cook shows up and does something 71 00:05:41,800 --> 00:05:45,580 for me that I need to move on but then I get an access to a car. 72 00:05:45,610 --> 00:05:49,980 Now here is a challenge that often you know you have to think about it. 73 00:05:49,990 --> 00:05:55,480 So what happens after a while I need another French translator I'm somewhere else in my program where 74 00:05:55,480 --> 00:05:58,940 I'm in a different class when I'm writing a totally different thing. 75 00:05:59,050 --> 00:06:02,870 So I need to get another French translator and perhaps another one. 76 00:06:03,070 --> 00:06:04,380 And so on and so forth. 77 00:06:04,390 --> 00:06:10,630 I need to get access to more cooks and more cars and more of almost everything simply because in the 78 00:06:10,630 --> 00:06:16,560 concept of all the constantly adds more and more instances of differing classes. 79 00:06:16,570 --> 00:06:20,980 So here we run into an issue and that issue is the memory management. 80 00:06:20,980 --> 00:06:27,010 If this was a real life example and I had to hire a cook to cook food for me and then the next day I 81 00:06:27,010 --> 00:06:28,380 had to hire another cook. 82 00:06:28,420 --> 00:06:34,390 And then by the end of the month I would have 30 cooks sitting at my home and that's what we call memory 83 00:06:34,390 --> 00:06:35,500 management. 84 00:06:35,500 --> 00:06:41,830 Once we get an object of a Class A does something for us such as doing a French translation the very 85 00:06:41,830 --> 00:06:47,860 first time then we say well your work is not deallocate you because I don't need that anymore. 86 00:06:48,070 --> 00:06:53,410 And then we do the same thing so on and so forth with every object that we don't need. 87 00:06:53,470 --> 00:07:01,630 Now once we get rid of all of these things what is intact is these classes the blueprints for making 88 00:07:01,630 --> 00:07:08,230 another cook or blueprint for making another French translation or another car that is stays intact. 89 00:07:08,230 --> 00:07:14,270 We can always access them but those objects we just use them temporary and then ones we don't need them. 90 00:07:14,440 --> 00:07:15,550 We get rid of them. 91 00:07:15,550 --> 00:07:19,190 It's very similar to when you have a button and you have a text field. 92 00:07:19,390 --> 00:07:27,820 You say get the text fields text put them in a string and that string printed so that NASA string it 93 00:07:27,820 --> 00:07:35,020 gets initialized and allocated for a short amount of time does something and then gets deallocated. 94 00:07:35,020 --> 00:07:41,260 So we don't have to worry about the memory that you're essentially investing or let's call it a vase 95 00:07:41,260 --> 00:07:46,570 thing and then we'll talk about this in far more detail when we talking about the memory management 96 00:07:46,570 --> 00:07:48,160 in a few lessons from now. 97 00:07:48,400 --> 00:07:57,010 So in a nutshell that's a concept for object oriented programming objects such as core one made of classes 98 00:07:57,010 --> 00:08:03,640 such as car that knows how to make different cars every object based on their parent. 99 00:08:03,670 --> 00:08:10,540 They have a set of things they can do that we call functions in a case of a car such as changing gears. 100 00:08:10,750 --> 00:08:17,560 In a case of a cooking light such as cooking a certain recipe and they have some attributes in case 101 00:08:17,560 --> 00:08:23,440 of a car that's would could be the color in case of a translation that's cheap Be it could be the language 102 00:08:23,440 --> 00:08:25,320 that is going to translate for us. 103 00:08:25,360 --> 00:08:26,680 So on and so forth. 104 00:08:26,680 --> 00:08:32,860 So with that in mind I'm going to move on to our next lesson where we can actually begin writing our 105 00:08:32,920 --> 00:08:34,330 own classes. 106 00:08:34,330 --> 00:08:39,130 We have been using them so far but this time we're actually going to write our own version of things 107 00:08:39,190 --> 00:08:44,020 and get a better sense of how all works in Strief in Objective-C.