1
00:00:00,030 --> 00:00:04,500
Hey! Welcome to Day 16 of 100 Days of Code. Now

2
00:00:04,530 --> 00:00:05,100
today,

3
00:00:05,100 --> 00:00:08,250
we're going to be pulling out the big guns, we're going to be learning about

4
00:00:08,280 --> 00:00:12,210
Object Oriented Programming otherwise known as OOP.

5
00:00:12,630 --> 00:00:16,890
Why are we learning about it? Well, if you think back to yesterday's project,

6
00:00:17,310 --> 00:00:21,450
some of you I'm sure at some point during the project, would have had this

7
00:00:21,450 --> 00:00:25,740
feeling of what on earth is going on with my code?

8
00:00:25,920 --> 00:00:30,060
And the reason is because our code is getting more complex,

9
00:00:30,330 --> 00:00:32,369
it's trying to do a lot of things,

10
00:00:32,490 --> 00:00:35,850
and it's trying to manage a whole bunch of relationships.

11
00:00:36,150 --> 00:00:39,540
So one function is changing a variable,

12
00:00:39,540 --> 00:00:43,740
and then that same function is doing something else to another variable.

13
00:00:44,100 --> 00:00:48,810
And at some point, the logic of our code starts looking very, very spaghetti-

14
00:00:48,810 --> 00:00:49,643
like.

15
00:00:49,920 --> 00:00:54,630
And it's at this point where it's really hard to track and remember what's

16
00:00:54,720 --> 00:00:56,460
actually going on in our code.

17
00:00:57,180 --> 00:01:00,510
So this style of programming is called Procedural

18
00:01:00,510 --> 00:01:05,510
Programming where we set up procedures or functions that do particular things.

19
00:01:06,600 --> 00:01:11,250
And then one procedure leads to another procedure, and all in all, the computer's

20
00:01:11,250 --> 00:01:15,690
mostly working from top to bottom and then jumping out into a function as

21
00:01:15,690 --> 00:01:16,523
needed.

22
00:01:17,250 --> 00:01:22,110
Procedural programming is one of the earliest paradigms of Programming.

23
00:01:22,410 --> 00:01:27,210
In fact, back in the days when we had older languages like Fortran and COBOL,

24
00:01:27,840 --> 00:01:30,840
they rely pretty much exclusively on procedural

25
00:01:30,840 --> 00:01:32,670
programming like what we've been doing.

26
00:01:33,780 --> 00:01:36,120
But the increase in complexity,

27
00:01:36,150 --> 00:01:40,410
the increase in the number of relationships that we need to remember and manage

28
00:01:40,800 --> 00:01:45,540
starts making it look a bit like the dating history of the Kardashians.

29
00:01:45,930 --> 00:01:47,160
And it gets very,

30
00:01:47,160 --> 00:01:52,020
very confusing because everybody has been in touch with somebody else. Now,

31
00:01:52,080 --> 00:01:56,280
the kind of relationships I prefer are one to one, me and my couch.

32
00:01:56,700 --> 00:02:01,700
So how can we maintain a simple relationship in our code while being able to

33
00:02:03,120 --> 00:02:07,320
write more and more complex projects? Well,

34
00:02:07,350 --> 00:02:11,430
this is where the Object-Oriented paradigm comes in really handy.

35
00:02:12,090 --> 00:02:17,090
Now let's imagine that you're tasked with creating the program for a self-

36
00:02:18,150 --> 00:02:21,090
driving car. Now, as you can imagine,

37
00:02:21,090 --> 00:02:24,660
this is a pretty complex project and it's many,

38
00:02:24,660 --> 00:02:29,220
many notches above the coffee machine that we've been struggling with so far.

39
00:02:29,970 --> 00:02:33,630
But what if you broke it down? What is a self-driving car?

40
00:02:34,020 --> 00:02:38,160
What are the different components that make up a self-driving car? Well,

41
00:02:38,220 --> 00:02:43,220
it probably needs some sort of camera module to keep track of what's on the road

42
00:02:43,560 --> 00:02:45,360
and to recognize what's on the road,

43
00:02:45,990 --> 00:02:50,990
it will probably need a form of lane detection to know if we're actually within

44
00:02:51,750 --> 00:02:56,750
the lane or if we need to turn off or if we need to park, and it will need some

45
00:02:58,560 --> 00:03:02,740
way of navigating so that when the user says, I want to go to the bank,

46
00:03:02,980 --> 00:03:05,290
they identify the branch they want to go to,

47
00:03:05,380 --> 00:03:09,370
and then the navigation gets set up and the car knows how to get there.

48
00:03:09,940 --> 00:03:14,080
And finally, you'll probably need some form of fuel management, right?

49
00:03:14,140 --> 00:03:16,330
What should happen when the fuel gets low?

50
00:03:16,660 --> 00:03:20,290
Should it go and automatically recharge at a specified point?

51
00:03:20,800 --> 00:03:24,010
Now I'm obviously simplifying this task. There's a lot,

52
00:03:24,010 --> 00:03:27,160
a lot more that goes into making an automated car.

53
00:03:27,730 --> 00:03:32,140
But we've already managed to break it down into several modules that we can

54
00:03:32,320 --> 00:03:34,000
think about tackling, right?

55
00:03:34,540 --> 00:03:39,540
But imagine if you have a whole team who are all working on this project and

56
00:03:39,790 --> 00:03:40,750
within that team,

57
00:03:40,750 --> 00:03:45,010
there's sub-teams who are working on each of these different modules.

58
00:03:45,490 --> 00:03:50,490
Well then by splitting up this big complex task into separate modules,

59
00:03:51,520 --> 00:03:54,640
then we can all work on this car simultaneously,

60
00:03:55,570 --> 00:03:57,820
massively improving our productivity,

61
00:03:58,180 --> 00:04:02,500
making it much quicker to eventually build all the software for this car.

62
00:04:03,280 --> 00:04:06,850
Plus on top of that, a lot of these modules are reusable.

63
00:04:07,270 --> 00:04:12,270
So if it just so happens that the next year we're tasked with building a drone,

64
00:04:12,640 --> 00:04:16,390
well, a lot of those programming modules that we built, like the camera module,

65
00:04:16,390 --> 00:04:18,700
the fuel management, the navigation,

66
00:04:18,910 --> 00:04:23,910
that's all going to be incredibly useful in our drone delivery software as well.

67
00:04:24,370 --> 00:04:29,370
And because we've taken out these individual chunks of code and modularized them

68
00:04:29,890 --> 00:04:32,020
using Object Oriented Programming,

69
00:04:32,260 --> 00:04:36,340
we won't have to code them up again in the same way that we might need to

70
00:04:36,460 --> 00:04:38,380
if we were using procedural programming.

71
00:04:39,180 --> 00:04:44,180
So what exactly is all Object Oriented Programming? We've seen that we can split

72
00:04:46,140 --> 00:04:49,620
a larger task into that smaller pieces.

73
00:04:50,070 --> 00:04:54,690
And each of those pieces can be worked on by separate teams, separate people,

74
00:04:54,990 --> 00:04:59,460
and also each of those pieces become reusable if we need the same

75
00:04:59,460 --> 00:05:03,030
functionality in the future. But Object Oriented

76
00:05:03,030 --> 00:05:05,940
Programming actually takes that concept even further.

77
00:05:06,510 --> 00:05:08,130
And I think the best way to explain it

78
00:05:08,340 --> 00:05:11,730
is to imagine that you are tasked with running a restaurant.

79
00:05:12,420 --> 00:05:16,320
So you take over this restaurant from your long lost uncle

80
00:05:16,440 --> 00:05:19,980
and you realize that it's actually really hard running a restaurant.

81
00:05:20,550 --> 00:05:25,550
So, first off, you have to be the receptionist and you reserve seats for your

82
00:05:26,220 --> 00:05:29,400
restaurant visitor's and then when they order something,

83
00:05:29,430 --> 00:05:32,520
you have to be the waitress and bring them their order.

84
00:05:32,970 --> 00:05:35,370
And then of course the order needs to be cooked up, right?

85
00:05:35,370 --> 00:05:39,600
So you're also gonna run into the kitchen and be the chef, create the thing that

86
00:05:39,600 --> 00:05:41,130
they ordered and finally,

87
00:05:41,130 --> 00:05:44,550
you're also going to be the cleaner tidying up after everybody

88
00:05:44,580 --> 00:05:47,070
once they've left. As you can imagine,

89
00:05:47,070 --> 00:05:50,280
if you were one person having to do all of these tasks,

90
00:05:50,730 --> 00:05:55,410
that's going to be a pretty rough day. There are in fact one-man restaurants,

91
00:05:55,500 --> 00:05:58,310
and I've seen some work really in well Japan,

92
00:05:58,700 --> 00:06:01,970
where you have one person who's taking the order,

93
00:06:02,300 --> 00:06:05,300
who's making the food, who's tidying up after you.

94
00:06:05,720 --> 00:06:10,040
But the limitation here though, is that look at how many seats he has.

95
00:06:10,190 --> 00:06:15,190
You can't have a large restaurant running everything by yourself. In the same

96
00:06:16,340 --> 00:06:20,780
way we can't create a very complex and really large software project

97
00:06:21,170 --> 00:06:25,370
if we are using a procedural style of programming where we're sort of running a

98
00:06:25,370 --> 00:06:27,380
one man band. It gets very,

99
00:06:27,380 --> 00:06:30,620
very complex and very hard to manage very quickly.

100
00:06:31,280 --> 00:06:33,260
So lets consider the alternative.

101
00:06:33,770 --> 00:06:38,770
What if we had just hired a bunch of people where they each have their own

102
00:06:39,290 --> 00:06:42,590
individual roles. They're trained for it, they know what to do.

103
00:06:42,800 --> 00:06:46,940
The waiter knows how to wait and the chef knows how to cook. Well,

104
00:06:46,940 --> 00:06:47,600
in this case,

105
00:06:47,600 --> 00:06:52,600
you could just be the manager and you can manage all of your staff and tell them

106
00:06:53,210 --> 00:06:54,560
what it is that they need to do.

107
00:06:54,980 --> 00:06:59,510
But then you won't have to worry about the nitty-gritty details of exactly how

108
00:06:59,510 --> 00:07:02,660
they need to go about doing their jobs. So for example,

109
00:07:02,660 --> 00:07:04,040
you don't need to tell the waiter

110
00:07:04,050 --> 00:07:08,300
how to wait on customers and you don't need to tell the chef how to cook an egg

111
00:07:08,450 --> 00:07:10,370
because they already know how to do that.

112
00:07:11,000 --> 00:07:16,000
And we can use the same concept to simplify the relationships in our code and

113
00:07:17,090 --> 00:07:21,080
make it scalable for a larger and more complex project.

