1
00:00:00,240 --> 00:00:05,240
Now as we start using objects and their attributes and methods more and more,

2
00:00:05,640 --> 00:00:10,410
we're going to start to see why it is that they are so useful and so loved by

3
00:00:10,410 --> 00:00:12,120
programmers. Now,

4
00:00:12,150 --> 00:00:17,150
I think one of the non-programmers that explained OOP the best is actually the late

5
00:00:18,350 --> 00:00:19,183
Steve Jobs.

6
00:00:19,730 --> 00:00:24,730
And he has this brilliant example that makes it really clear why objects are so

7
00:00:25,880 --> 00:00:28,100
great. In his story

8
00:00:28,280 --> 00:00:33,280
he talks about this concept where let's say you were traveling to Japan and

9
00:00:33,440 --> 00:00:35,450
after a long flight,

10
00:00:36,020 --> 00:00:40,910
you finally land and you go outside and there's beautiful cherry blossoms, Mt.

11
00:00:40,910 --> 00:00:44,270
Fuji is looking wonderful. But unfortunately on the flight,

12
00:00:44,630 --> 00:00:45,920
you had soiled your T-shirt.

13
00:00:45,950 --> 00:00:50,950
You were overly eager with the tomato juice and you spilled everything upon

14
00:00:51,560 --> 00:00:55,460
yourself. So what do we do? Well,

15
00:00:55,520 --> 00:00:58,700
you're in this unfamiliar city and you have no idea

16
00:00:58,730 --> 00:01:02,420
even whether the hell you are let alone where to find the nearest

17
00:01:02,600 --> 00:01:06,320
dry cleaners or launderette. And plus on top of that,

18
00:01:06,380 --> 00:01:09,470
you don't have the local currency. They take yen,

19
00:01:09,500 --> 00:01:14,240
but you only have pounds and you don't even speak Japanese. So what do you do?

20
00:01:14,750 --> 00:01:18,890
It's going to be a real struggle trying to solve this problem. Well,

21
00:01:19,130 --> 00:01:22,970
you staying at a hotel, right? And the hotel staff probably speak English.

22
00:01:23,420 --> 00:01:28,250
So you go the receptionist and you tell it the hotel that, Hey,

23
00:01:28,280 --> 00:01:32,270
my t-shirt is soiled and they say, Hey, no problems. We'll take that from you.

24
00:01:32,420 --> 00:01:35,240
And we'll go and handle all of that messy stuff.

25
00:01:35,540 --> 00:01:37,280
We know how to find the dry cleaners,

26
00:01:37,550 --> 00:01:40,820
we can pay them in the local currency and we speak the local language.

27
00:01:41,270 --> 00:01:44,990
And what you get back is just a nice clean t-shirt.

28
00:01:45,500 --> 00:01:50,360
So this is similar to the process of working with objects. Essentially,

29
00:01:50,360 --> 00:01:52,640
if you have this hotel object

30
00:01:52,790 --> 00:01:56,450
which has a blueprint for how to handle dry cleaning

31
00:01:56,510 --> 00:02:01,510
some sort of clothing, then all you have to do is just get the object hotel and

32
00:02:03,170 --> 00:02:06,500
then call its associated method dry clean,

33
00:02:06,920 --> 00:02:10,039
and then it will do all of the messy stuff for you.

34
00:02:10,280 --> 00:02:14,090
And you don't have to worry about the implementation of this function at all.

35
00:02:14,750 --> 00:02:18,020
So now you can work with multiple objects

36
00:02:18,350 --> 00:02:23,330
getting them to do different things and trust that they know how to manage their

37
00:02:23,330 --> 00:02:26,510
data and how to perform the necessary functionality.

38
00:02:27,350 --> 00:02:30,410
Coming back to a problem that we've already solved

39
00:02:30,710 --> 00:02:35,090
creating that coffee machine with all of the program requirements. Well,

40
00:02:35,090 --> 00:02:39,740
it's time to put our Object Oriented Programming knowledge to the test because

41
00:02:39,740 --> 00:02:44,180
we're going to be making a OOP version of our coffee machine.

42
00:02:44,990 --> 00:02:48,020
Now the program still has the same requirements

43
00:02:48,020 --> 00:02:51,050
as before. You have to print reports for

44
00:02:51,050 --> 00:02:54,350
all the resources, you have to check if the resources are sufficient,

45
00:02:54,530 --> 00:02:59,530
process coins, check transaction is successful, and finally make coffee.

46
00:03:00,100 --> 00:03:03,700
But in this case, you're going to be working with objects.

47
00:03:04,810 --> 00:03:06,220
In the course resources,

48
00:03:06,250 --> 00:03:11,110
you'll find a link to the starting project for the OOP coffee machine.

49
00:03:11,620 --> 00:03:13,090
So if you head over to this link,

50
00:03:13,240 --> 00:03:17,170
you can see that there's a whole bunch of code that we've already written for

51
00:03:17,170 --> 00:03:18,250
you. Now,

52
00:03:18,280 --> 00:03:22,300
the idea here is you're not going to touch any of these other files,

53
00:03:22,300 --> 00:03:27,160
the money machine, the menu, or the coffee maker. All that code has already

54
00:03:27,160 --> 00:03:28,360
been written for you

55
00:03:28,690 --> 00:03:31,750
and it's almost like you're working with an external library.

56
00:03:32,260 --> 00:03:35,020
You're just going to trust that they do what they say they do.

57
00:03:35,980 --> 00:03:40,270
And you'll find a link to this coffee machine documentation that I've created

58
00:03:40,630 --> 00:03:45,630
which describes in detail what each of these classes or blueprints allow you to

59
00:03:46,390 --> 00:03:50,560
do. So once you construct an object from the menu item class,

60
00:03:50,830 --> 00:03:54,340
then you have access to the name attribute, the cost attribute,

61
00:03:54,340 --> 00:03:58,690
ingredient attributes, and there's also descriptions of what it should do

62
00:03:58,930 --> 00:04:00,610
and what an example might be.

63
00:04:01,450 --> 00:04:05,860
You have access to all of these classes and you can build objects from each of

64
00:04:05,860 --> 00:04:08,620
these classes to solve this project.

65
00:04:09,670 --> 00:04:13,540
In order to work with PyCharm, all you need to do is to download the zip

66
00:04:13,540 --> 00:04:16,810
file it with all the starting code from our course resource website.

67
00:04:17,260 --> 00:04:18,160
Alternatively,

68
00:04:18,190 --> 00:04:22,270
if you are already logged in on Repl.it, simply fork the project and then click

69
00:04:22,270 --> 00:04:26,350
on these three dots to download the zip file here. Now,

70
00:04:26,350 --> 00:04:28,510
once you found that in your downloads folder,

71
00:04:28,540 --> 00:04:31,450
all you have to do is uncompressed or unzip it.

72
00:04:32,020 --> 00:04:35,140
And then you can go into PyCharm and open it here.

73
00:04:35,260 --> 00:04:40,030
So click on the open button and then navigate to where you had that folder

74
00:04:40,030 --> 00:04:43,330
downloaded. Remember it needs to be unzipped.

75
00:04:44,260 --> 00:04:48,550
If you're on windows, right-click the zip file and choose extract all.

76
00:04:48,880 --> 00:04:50,260
Then click extract.

77
00:04:50,560 --> 00:04:54,280
You should see an unzipped folder popup next to your zip file.

78
00:04:55,240 --> 00:05:00,240
If you're on Mac then all you need to do is just double-click on the .zip file.

79
00:05:01,750 --> 00:05:04,000
Now, if we click open on that folder,

80
00:05:04,660 --> 00:05:08,740
then it will open up this project. And when you open up the project folder,

81
00:05:08,770 --> 00:05:11,230
you'll see all of the same files.

82
00:05:11,770 --> 00:05:16,300
Now you're only going to be working from the main.py. In fact,

83
00:05:16,300 --> 00:05:20,200
I don't even want you to care that much about the code that's in the other

84
00:05:20,200 --> 00:05:21,033
files.

85
00:05:21,190 --> 00:05:25,840
It has class definitions and a whole bunch of other things that we're going to

86
00:05:25,840 --> 00:05:27,370
learn about in the next lesson.

87
00:05:27,790 --> 00:05:32,170
But for now, I want you to treat it as if it is an external library

88
00:05:32,350 --> 00:05:37,000
which you're just going to use. At the very beginning of the main.py file,

89
00:05:37,060 --> 00:05:41,380
I've already imported all four classes that you are going to be using; menu,

90
00:05:41,410 --> 00:05:44,110
menu item, coffee maker, and money machine.

91
00:05:44,800 --> 00:05:49,690
Now all of these classes are documented in the coffee machine documentation

92
00:05:49,690 --> 00:05:50,523
website.

93
00:05:50,800 --> 00:05:55,800
All you have to do is head over to this website and read through what each of

94
00:05:56,140 --> 00:05:59,930
the classes do. Some of them have attributes and methods,

95
00:06:00,260 --> 00:06:02,120
others just have methods.

96
00:06:02,720 --> 00:06:07,720
So each of these classes have already pre-written code that do a lot of the

97
00:06:08,450 --> 00:06:12,740
heavy lifting and all of the code that we had to write when we wrote the coffee

98
00:06:12,740 --> 00:06:14,330
machine code from scratch.

99
00:06:14,810 --> 00:06:19,790
But this time you're only going to be using these four classes and the objects

100
00:06:19,790 --> 00:06:24,470
created from them in order to achieve exactly the same goals as before.

101
00:06:25,100 --> 00:06:29,120
So while the goals are fresh in your mind from the previous day,

102
00:06:29,540 --> 00:06:33,500
you should review the code from the previous day and then have a read of the

103
00:06:33,500 --> 00:06:38,500
documentation and see how you would implement exactly the same project

104
00:06:38,930 --> 00:06:43,310
but this time using only the objects created from these classes.

105
00:06:43,880 --> 00:06:47,300
You'll need to spend some time on this because you'll need to think through how

106
00:06:47,300 --> 00:06:52,300
to create objects from these blueprint classes and then how to use the objects,

107
00:06:52,510 --> 00:06:56,420
how to call the methods and the logic that's required to put everything

108
00:06:56,420 --> 00:06:58,430
together. Pause the video

109
00:06:58,430 --> 00:07:02,480
now, have a think about this problem, and try to make the coffee machine do

110
00:07:02,480 --> 00:07:07,480
exactly the same and have all the same functionality as the coffee machine that

111
00:07:08,030 --> 00:07:10,190
you created in yesterday's project.

