1 00:00:00,210 --> 00:00:04,350 Now, if you're just learning to code, you've seen this word class and you've probably wondered, what 2 00:00:04,350 --> 00:00:04,920 does it mean? 3 00:00:05,700 --> 00:00:08,030 Well, it's a way of grouping stuff logically. 4 00:00:08,730 --> 00:00:12,960 So if we had a class that represented a dog, we could put some variables in it. 5 00:00:13,260 --> 00:00:18,750 Let legs equals four because dogs have four legs and let tail equals true because they have tails. 6 00:00:19,500 --> 00:00:23,040 We can also have a function called Wolf, which prints out Wolf for us. 7 00:00:24,060 --> 00:00:30,450 So what this class does is illogically arrange all of the properties that a dog has and all of the functions 8 00:00:30,450 --> 00:00:31,410 that a dog has. 9 00:00:32,160 --> 00:00:37,190 Classes are the fundamental structure that we use to organize our code. 10 00:00:37,500 --> 00:00:42,060 So you might have something like a class to fetch a Eurail from your observer. 11 00:00:42,240 --> 00:00:45,750 You'll have a class to share something via Facebook. 12 00:00:45,750 --> 00:00:48,090 You'll have classes to do all of these things. 13 00:00:48,600 --> 00:00:54,750 And in fact, well, I'm not going to say that's a class because I don't think it is, but it is I think. 14 00:00:55,590 --> 00:00:56,430 Ignore me on that. 15 00:00:56,860 --> 00:00:59,370 I have to explore that a bit more anyway. 16 00:01:00,380 --> 00:01:03,020 Class dog is. 17 00:01:04,420 --> 00:01:10,030 A blueprint, right, a blueprint doesn't exist. 18 00:01:10,390 --> 00:01:17,920 Yes, I know you can see the code, but it doesn't actually exist yet as an object because blueprints 19 00:01:17,920 --> 00:01:22,150 make objects, classes make objects. 20 00:01:22,630 --> 00:01:28,990 So when you hear the word object in programming, it's because someone went to a class called Doug open 21 00:01:28,990 --> 00:01:29,980 and close some brackets. 22 00:01:30,130 --> 00:01:31,450 Now it's an object. 23 00:01:31,480 --> 00:01:33,130 Now the dog is real. 24 00:01:34,760 --> 00:01:37,760 Left froglet dog equal to dog. 25 00:01:38,920 --> 00:01:44,840 OK, so now that I have that object, I can start making it do whatever I want. 26 00:01:44,860 --> 00:01:46,140 I would like you to, Wolf. 27 00:01:46,780 --> 00:01:50,650 And so when I hit play, that is going to print out Wolf for us. 28 00:01:52,790 --> 00:01:56,450 OK, so a class is a fundamental way of organizing things. 29 00:01:57,220 --> 00:01:59,870 Now, what if I had a cat? 30 00:02:00,050 --> 00:02:02,590 So I'm just going to copy the first part of my notes here. 31 00:02:06,540 --> 00:02:11,340 And this cat is like the dog, it has legs, a tail, it has a name and it has meow. 32 00:02:12,030 --> 00:02:15,900 Now legs and tails always stays like that, basically. 33 00:02:17,000 --> 00:02:20,420 Cat's always meow, right, but what about this name? 34 00:02:20,990 --> 00:02:23,270 How do we fill that in? 35 00:02:23,270 --> 00:02:26,360 Because every cat has a different name. 36 00:02:27,260 --> 00:02:30,530 What we can use is the Init function. 37 00:02:30,920 --> 00:02:39,290 Now in it is a special function that gets called whenever the class creates something from itself, 38 00:02:39,300 --> 00:02:42,830 whenever this blueprint turns into a cat object. 39 00:02:44,240 --> 00:02:52,940 The in it allows you to pass arguments over just like any other function, and then once you've passed 40 00:02:52,940 --> 00:03:01,310 the argument over, you can do stuff with it so you can say set self-taught name self simply refers 41 00:03:01,310 --> 00:03:04,250 to the current object of this cat. 42 00:03:05,320 --> 00:03:10,600 And we the reason we use it is because we have a name here and a name here, and we need to distinguish 43 00:03:10,600 --> 00:03:12,050 which one we're talking about. 44 00:03:12,430 --> 00:03:15,670 So this one refers to that. 45 00:03:16,600 --> 00:03:25,960 And this one refers to that, right, so we're setting the name of this object to the name we've passed 46 00:03:25,960 --> 00:03:30,660 in and so we can have our cat is equal to Cat. 47 00:03:31,120 --> 00:03:37,390 And you'll notice this gives an error because it says I need to have a name for the in it parameter. 48 00:03:38,640 --> 00:03:41,520 So we say, fine, you may have Felix. 49 00:03:43,970 --> 00:03:48,950 Now, when we hit play, we get our cat called Felix, how do we know he's called Felix? 50 00:03:48,950 --> 00:03:51,650 But we can say cat dot name. 51 00:03:54,180 --> 00:04:00,640 And there we have Felix passed in, so this in it actually is short for initialise. 52 00:04:00,750 --> 00:04:04,890 It's the thing that creates the object from the class, if you like. 53 00:04:04,890 --> 00:04:09,630 The thing that kicks it all off well, it doesn't kick it off, does something further down the chain. 54 00:04:09,630 --> 00:04:12,870 But we don't need to worry about those specifics right now. 55 00:04:13,530 --> 00:04:16,170 So I've got some homework for you with classes. 56 00:04:17,330 --> 00:04:22,820 And here it is, create a class for an accounts package, account software. 57 00:04:23,270 --> 00:04:24,830 I want you to have two variables. 58 00:04:25,490 --> 00:04:29,060 One store's income, one store's expenses, just integers. 59 00:04:30,210 --> 00:04:38,100 Create two functions that add the expense variable and the other one to add to the income variable. 60 00:04:38,710 --> 00:04:43,290 OK, this is the first part of the homework we're going to carry on with this class concept. 61 00:04:43,680 --> 00:04:46,290 So that's probably not that difficult. 62 00:04:46,770 --> 00:04:48,540 Go ahead and give that a go.