WEBVTT

0
00:00.060 --> 00:04.620
We've seen a little bit of why Object Oriented Programming is really useful,

1
00:04.980 --> 00:09.510
but now let's take a look at how you would actually go about implementing Object

2
00:09.510 --> 00:10.530
Oriented Programming.

3
00:11.370 --> 00:15.240
So in the last lesson we talked of this example of the restaurant,

4
00:15.750 --> 00:18.600
where we hired three types of staff,

5
00:19.020 --> 00:24.020
and we had a manager who would then manage all of these three different types of

6
00:24.300 --> 00:25.830
staff. Now,

7
00:26.160 --> 00:31.160
the reason why Object Oriented Programming is called that is because it's trying

8
00:31.410 --> 00:34.350
to model a real world object.

9
00:34.770 --> 00:39.570
So let's say that we are creating a virtual restaurant. Well, in this case,

10
00:39.570 --> 00:43.320
we probably have to model a virtual chef, waiter,

11
00:43.350 --> 00:44.760
cleaner, and manager.

12
00:45.270 --> 00:50.270
So let's say that we were going to model a waiter. In order to model our waiter,

13
00:50.910 --> 00:55.910
there's probably two things we need to think about: what it has and what it does.

14
00:56.790 --> 01:00.540
In terms of what it has, well, it might have variables like,

15
01:00.570 --> 01:02.790
is it holding a plate, true or false?

16
01:03.360 --> 01:08.360
Or which tables is it responsible for? Maybe table 4, 5 and 6.

17
01:09.510 --> 01:11.940
Now it also has things that it does.

18
01:12.390 --> 01:17.390
Maybe they're able to take an order to the chef and maybe they also need to take

19
01:17.670 --> 01:22.470
payments and add money to the restaurant. So these two different things,

20
01:22.500 --> 01:25.650
what the waiter has and what the waiter does are

21
01:25.650 --> 01:30.650
the two most important things that make up an object: its attributes and its

22
01:32.520 --> 01:34.980
methods. By looking at the code,

23
01:35.010 --> 01:39.750
you can pretty much see that the attributes is basically a variable.

24
01:40.260 --> 01:45.260
An attribute is just a fancy word for a variable that's associated with a

25
01:46.410 --> 01:48.660
modeled object like our waiter here.

26
01:49.260 --> 01:52.500
Because it's not just a free floating bit of a variable, right?

27
01:52.500 --> 01:54.690
It's not just somewhere in our main.py.

28
01:55.050 --> 01:59.130
It's actually a variable that's attached to a particular object.

29
01:59.400 --> 02:02.130
It's the waiter's tables responsible.

30
02:02.850 --> 02:05.970
Now the method goes along the same vein. These,

31
02:06.060 --> 02:08.520
as you can clearly see, are just functions

32
02:09.090 --> 02:14.090
but we call it a method because it's a function that a particular modeled

33
02:14.730 --> 02:16.500
object can do.

34
02:17.160 --> 02:22.160
We need a waiter object to take the order and we need a waiter object to take

35
02:22.260 --> 02:25.950
payment. Again, these are not just free-floating functions.

36
02:26.520 --> 02:31.520
Now, there's a lot of new words that are part of Object Oriented Programming and

37
02:31.740 --> 02:35.160
programming in general, we're going to see them again and again,

38
02:35.220 --> 02:38.160
and eventually it's going to become a word that's going to be in your

39
02:38.160 --> 02:42.720
dictionary. But for now, just remember that in Object Oriented

40
02:42.720 --> 02:43.350
Programming,

41
02:43.350 --> 02:48.350
we're trying to model real-life objects and those objects have things

42
02:49.590 --> 02:51.720
and they also can do things.

43
02:52.110 --> 02:54.780
The things that they have are their attributes

44
02:55.200 --> 02:59.980
and these are usually modeled with variables, and the things that they can do

45
03:00.280 --> 03:03.400
are called methods and they are modeled by functions.

46
03:04.060 --> 03:09.060
So essentially, an object is just a way of combining some piece of data and some

47
03:10.810 --> 03:14.170
functionality altogether in the same thing.

48
03:15.370 --> 03:20.370
But we can actually have multiple objects generated from the same type.

49
03:21.190 --> 03:24.940
So when we've modeled a particular job in our virtual restaurant

50
03:25.030 --> 03:26.800
like the waiter's job,

51
03:27.490 --> 03:31.090
and we figured out what are the things that the waiter have and what are the

52
03:31.090 --> 03:33.220
things that it can do, well,

53
03:33.220 --> 03:38.220
we can actually generate multiple versions of the same object. So we could have

54
03:38.950 --> 03:43.270
Henry who's a waiter and we can also have Betty who's a waiter,

55
03:43.840 --> 03:48.460
and we can generate as many of these as we want from the same blueprint.

56
03:48.970 --> 03:53.970
And in OOP we call this blueprint, or this type, a class.

57
03:56.170 --> 04:01.170
And we call these individual objects that are generated from the blueprint

58
04:01.480 --> 04:02.320
an object.

59
04:03.070 --> 04:08.070
So now let's take a look at how you use these class blueprints to create an actual

60
04:08.380 --> 04:08.950
object.