WEBVTT

0
00:00.030 --> 00:04.500
Hey! Welcome to Day 16 of 100 Days of Code. Now

1
00:04.530 --> 00:05.100
today,

2
00:05.100 --> 00:08.250
we're going to be pulling out the big guns, we're going to be learning about

3
00:08.280 --> 00:12.210
Object Oriented Programming otherwise known as OOP.

4
00:12.630 --> 00:16.890
Why are we learning about it? Well, if you think back to yesterday's project,

5
00:17.310 --> 00:21.450
some of you I'm sure at some point during the project, would have had this

6
00:21.450 --> 00:25.740
feeling of what on earth is going on with my code?

7
00:25.920 --> 00:30.060
And the reason is because our code is getting more complex,

8
00:30.330 --> 00:32.370
it's trying to do a lot of things,

9
00:32.490 --> 00:35.850
and it's trying to manage a whole bunch of relationships.

10
00:36.150 --> 00:39.540
So one function is changing a variable,

11
00:39.540 --> 00:43.740
and then that same function is doing something else to another variable.

12
00:44.100 --> 00:48.810
And at some point, the logic of our code starts looking very, very spaghetti-

13
00:48.810 --> 00:49.643
like.

14
00:49.920 --> 00:54.630
And it's at this point where it's really hard to track and remember what's

15
00:54.720 --> 00:56.460
actually going on in our code.

16
00:57.180 --> 01:00.510
So this style of programming is called Procedural

17
01:00.510 --> 01:05.510
Programming where we set up procedures or functions that do particular things.

18
01:06.600 --> 01:11.250
And then one procedure leads to another procedure, and all in all, the computer's

19
01:11.250 --> 01:15.690
mostly working from top to bottom and then jumping out into a function as

20
01:15.690 --> 01:16.523
needed.

21
01:17.250 --> 01:22.110
Procedural programming is one of the earliest paradigms of Programming.

22
01:22.410 --> 01:27.210
In fact, back in the days when we had older languages like Fortran and COBOL,

23
01:27.840 --> 01:30.840
they rely pretty much exclusively on procedural

24
01:30.840 --> 01:32.670
programming like what we've been doing.

25
01:33.780 --> 01:36.120
But the increase in complexity,

26
01:36.150 --> 01:40.410
the increase in the number of relationships that we need to remember and manage

27
01:40.800 --> 01:45.540
starts making it look a bit like the dating history of the Kardashians.

28
01:45.930 --> 01:47.160
And it gets very,

29
01:47.160 --> 01:52.020
very confusing because everybody has been in touch with somebody else. Now,

30
01:52.080 --> 01:56.280
the kind of relationships I prefer are one to one, me and my couch.

31
01:56.700 --> 02:01.700
So how can we maintain a simple relationship in our code while being able to

32
02:03.120 --> 02:07.320
write more and more complex projects? Well,

33
02:07.350 --> 02:11.430
this is where the Object-Oriented paradigm comes in really handy.

34
02:12.090 --> 02:17.090
Now let's imagine that you're tasked with creating the program for a self-

35
02:18.150 --> 02:21.090
driving car. Now, as you can imagine,

36
02:21.090 --> 02:24.660
this is a pretty complex project and it's many,

37
02:24.660 --> 02:29.220
many notches above the coffee machine that we've been struggling with so far.

38
02:29.970 --> 02:33.630
But what if you broke it down? What is a self-driving car?

39
02:34.020 --> 02:38.160
What are the different components that make up a self-driving car? Well,

40
02:38.220 --> 02:43.220
it probably needs some sort of camera module to keep track of what's on the road

41
02:43.560 --> 02:45.360
and to recognize what's on the road,

42
02:45.990 --> 02:50.990
it will probably need a form of lane detection to know if we're actually within

43
02:51.750 --> 02:56.750
the lane or if we need to turn off or if we need to park, and it will need some

44
02:58.560 --> 03:02.740
way of navigating so that when the user says, I want to go to the bank,

45
03:02.980 --> 03:05.290
they identify the branch they want to go to,

46
03:05.380 --> 03:09.370
and then the navigation gets set up and the car knows how to get there.

47
03:09.940 --> 03:14.080
And finally, you'll probably need some form of fuel management, right?

48
03:14.140 --> 03:16.330
What should happen when the fuel gets low?

49
03:16.660 --> 03:20.290
Should it go and automatically recharge at a specified point?

50
03:20.800 --> 03:24.010
Now I'm obviously simplifying this task. There's a lot,

51
03:24.010 --> 03:27.160
a lot more that goes into making an automated car.

52
03:27.730 --> 03:32.140
But we've already managed to break it down into several modules that we can

53
03:32.320 --> 03:34.000
think about tackling, right?

54
03:34.540 --> 03:39.540
But imagine if you have a whole team who are all working on this project and

55
03:39.790 --> 03:40.750
within that team,

56
03:40.750 --> 03:45.010
there's sub-teams who are working on each of these different modules.

57
03:45.490 --> 03:50.490
Well then by splitting up this big complex task into separate modules,

58
03:51.520 --> 03:54.640
then we can all work on this car simultaneously,

59
03:55.570 --> 03:57.820
massively improving our productivity,

60
03:58.180 --> 04:02.500
making it much quicker to eventually build all the software for this car.

61
04:03.280 --> 04:06.850
Plus on top of that, a lot of these modules are reusable.

62
04:07.270 --> 04:12.270
So if it just so happens that the next year we're tasked with building a drone,

63
04:12.640 --> 04:16.390
well, a lot of those programming modules that we built, like the camera module,

64
04:16.390 --> 04:18.700
the fuel management, the navigation,

65
04:18.910 --> 04:23.910
that's all going to be incredibly useful in our drone delivery software as well.

66
04:24.370 --> 04:29.370
And because we've taken out these individual chunks of code and modularized them

67
04:29.890 --> 04:32.020
using Object Oriented Programming,

68
04:32.260 --> 04:36.340
we won't have to code them up again in the same way that we might need to

69
04:36.460 --> 04:38.380
if we were using procedural programming.

70
04:39.180 --> 04:44.180
So what exactly is all Object Oriented Programming? We've seen that we can split

71
04:46.140 --> 04:49.620
a larger task into that smaller pieces.

72
04:50.070 --> 04:54.690
And each of those pieces can be worked on by separate teams, separate people,

73
04:54.990 --> 04:59.460
and also each of those pieces become reusable if we need the same

74
04:59.460 --> 05:03.030
functionality in the future. But Object Oriented

75
05:03.030 --> 05:05.940
Programming actually takes that concept even further.

76
05:06.510 --> 05:08.130
And I think the best way to explain it

77
05:08.340 --> 05:11.730
is to imagine that you are tasked with running a restaurant.

78
05:12.420 --> 05:16.320
So you take over this restaurant from your long lost uncle

79
05:16.440 --> 05:19.980
and you realize that it's actually really hard running a restaurant.

80
05:20.550 --> 05:25.550
So, first off, you have to be the receptionist and you reserve seats for your

81
05:26.220 --> 05:29.400
restaurant visitor's and then when they order something,

82
05:29.430 --> 05:32.520
you have to be the waitress and bring them their order.

83
05:32.970 --> 05:35.370
And then of course the order needs to be cooked up, right?

84
05:35.370 --> 05:39.600
So you're also gonna run into the kitchen and be the chef, create the thing that

85
05:39.600 --> 05:41.130
they ordered and finally,

86
05:41.130 --> 05:44.550
you're also going to be the cleaner tidying up after everybody

87
05:44.580 --> 05:47.070
once they've left. As you can imagine,

88
05:47.070 --> 05:50.280
if you were one person having to do all of these tasks,

89
05:50.730 --> 05:55.410
that's going to be a pretty rough day. There are in fact one-man restaurants,

90
05:55.500 --> 05:58.310
and I've seen some work really in well Japan,

91
05:58.700 --> 06:01.970
where you have one person who's taking the order,

92
06:02.300 --> 06:05.300
who's making the food, who's tidying up after you.

93
06:05.720 --> 06:10.040
But the limitation here though, is that look at how many seats he has.

94
06:10.190 --> 06:15.190
You can't have a large restaurant running everything by yourself. In the same

95
06:16.340 --> 06:20.780
way we can't create a very complex and really large software project

96
06:21.170 --> 06:25.370
if we are using a procedural style of programming where we're sort of running a

97
06:25.370 --> 06:27.380
one man band. It gets very,

98
06:27.380 --> 06:30.620
very complex and very hard to manage very quickly.

99
06:31.280 --> 06:33.260
So lets consider the alternative.

100
06:33.770 --> 06:38.770
What if we had just hired a bunch of people where they each have their own

101
06:39.290 --> 06:42.590
individual roles. They're trained for it, they know what to do.

102
06:42.800 --> 06:46.940
The waiter knows how to wait and the chef knows how to cook. Well,

103
06:46.940 --> 06:47.600
in this case,

104
06:47.600 --> 06:52.600
you could just be the manager and you can manage all of your staff and tell them

105
06:53.210 --> 06:54.560
what it is that they need to do.

106
06:54.980 --> 06:59.510
But then you won't have to worry about the nitty-gritty details of exactly how

107
06:59.510 --> 07:02.660
they need to go about doing their jobs. So for example,

108
07:02.660 --> 07:04.040
you don't need to tell the waiter

109
07:04.050 --> 07:08.300
how to wait on customers and you don't need to tell the chef how to cook an egg

110
07:08.450 --> 07:10.370
because they already know how to do that.

111
07:11.000 --> 07:16.000
And we can use the same concept to simplify the relationships in our code and

112
07:17.090 --> 07:21.080
make it scalable for a larger and more complex project.