WEBVTT

00:00.200 --> 00:06.360
Now as we start using objects and their attributes and methods, more and more, we're going to start

00:06.360 --> 00:11.240
to see why it is that they are so useful and so loved by programmers.

00:11.760 --> 00:19.120
Now, I think one of the non-programmers that explained OOP the best is actually the late Steve Jobs,

00:19.680 --> 00:26.360
and he has this brilliant example that makes it really clear why objects are so great.

00:27.120 --> 00:34.880
In his story, he talks about this concept where let's say you were traveling to Japan and after a long

00:34.920 --> 00:40.560
flight, you finally land and you go outside and there's beautiful cherry blossoms.

00:40.560 --> 00:45.920
Mount Fuji is looking wonderful, but unfortunately, on the flight you had soiled your t shirt.

00:45.920 --> 00:52.280
You were overly eager with the tomato juice and you spilled everything on yourself.

00:52.840 --> 00:54.320
So what do we do?

00:54.840 --> 01:01.160
Well, you're in this unfamiliar city, and you have no idea even where the hell you are, let alone

01:01.220 --> 01:04.580
where to find the nearest dry cleaners or launderette.

01:04.940 --> 01:08.220
And plus, on top of that, you don't have the local currency.

01:08.420 --> 01:12.940
They take yen, but you only have pounds and you don't even speak Japanese.

01:13.220 --> 01:14.260
So what do you do?

01:14.660 --> 01:18.060
It's going to be a real struggle trying to solve this problem.

01:18.380 --> 01:20.660
Well, you're staying at a hotel, right?

01:20.700 --> 01:22.980
And the hotel staff probably speak English.

01:23.420 --> 01:29.900
So you go to the receptionist, and you tell the hotel that, hey, my t shirt is soiled, and they

01:29.900 --> 01:30.900
say, hey, no problem.

01:30.900 --> 01:35.300
We'll take that from you and we'll go and handle all of that messy stuff.

01:35.500 --> 01:37.460
We know how to find the dry cleaners.

01:37.460 --> 01:40.900
We can pay them in the local currency and we speak the local language.

01:41.220 --> 01:45.100
And what you get back is just a nice, clean t shirt.

01:45.460 --> 01:49.340
So this is similar to the process of working with objects.

01:49.660 --> 01:56.740
Essentially, if you have this hotel object which has a blueprint for how to handle dry cleaning some

01:56.780 --> 02:05.150
sort of clothing, then all you have to do is just get the object hotel and then call its associated

02:05.150 --> 02:06.550
method dry clean.

02:06.830 --> 02:10.190
And then it will do all of the messy stuff for you.

02:10.190 --> 02:14.150
And you don't have to worry about the implementation of this function at all.

02:14.750 --> 02:21.510
So now you can work with multiple objects, getting them to do different things and trust that they

02:21.510 --> 02:26.590
know how to manage their data and how to perform the necessary functionality.

02:27.310 --> 02:33.630
Coming back to a problem that we've already solved, creating that coffee machine with all of the program

02:33.630 --> 02:34.550
requirements.

02:34.790 --> 02:40.190
Well, it's time to put our object oriented programming knowledge to the test, because we're going

02:40.190 --> 02:44.270
to be making a OOP version of our coffee machine.

02:44.910 --> 02:48.590
Now, the program still has the same requirements as before.

02:48.590 --> 02:53.030
You have to print reports for all the resources you have to check.

02:53.030 --> 02:59.630
The resources are sufficient process coins, check transaction is successful, and finally make coffee.

02:59.990 --> 03:06.210
But in this case you're going to be working with objects in the course resources.

03:06.210 --> 03:11.210
You'll find a link to the starting project for the OOP coffee machine.

03:11.570 --> 03:16.530
So if you head over to this link, you can see that there's a whole bunch of code that we've already

03:16.530 --> 03:17.530
written for you.

03:17.930 --> 03:23.530
Now, the idea here is you're not going to touch any of these other files, the money machine, the

03:23.530 --> 03:25.450
menu or the coffee maker.

03:25.850 --> 03:31.210
All of that code is already been written for you, and it's almost like you're working with an external

03:31.210 --> 03:31.850
library.

03:32.170 --> 03:35.050
You're just going to trust that they do what they say they do.

03:35.930 --> 03:42.250
And you'll find a link to this coffee machine documentation that I've created, which describes in detail

03:42.410 --> 03:46.730
what each of these classes or blueprints allow you to do.

03:47.050 --> 03:53.250
So once you construct an object from the menu item class, then you have access to the name attribute,

03:53.250 --> 03:55.650
the cost attribute, ingredient attribute.

03:55.970 --> 04:00.690
And there's also descriptions of what it should do and what an example might be.

04:01.410 --> 04:07.660
You have access to all of these classes, and you can build objects from each of these classes to solve

04:07.660 --> 04:08.740
this project.

04:09.580 --> 04:14.820
In order to work with PyCharm, all you need to do is to download the zip file with all the starting

04:14.820 --> 04:16.900
code from our course resource website.

04:17.220 --> 04:22.660
Alternatively, now once you found that in your downloads folder, all you have to do is uncompress

04:22.660 --> 04:27.420
or unzip it, and then you can go into PyCharm and open it here.

04:27.420 --> 04:33.060
So click on the open button and then navigate to where you had that folder downloaded.

04:33.340 --> 04:35.580
Remember it needs to be unzipped.

04:36.340 --> 04:40.700
If you're on windows right click the zip file and choose Extract All.

04:40.980 --> 04:42.500
Then click extract.

04:42.660 --> 04:46.500
You should see an unzipped folder pop up next to your zip file.

04:47.340 --> 04:53.180
If you're on Mac, then all you need to do is just double click on the zip file.

04:53.860 --> 04:59.060
Now if we click open on that folder, then it will open up this project.

04:59.060 --> 05:03.600
And when you open up the project folder you'll see all of the same files.

05:03.920 --> 05:07.400
Now you're only going to be working from the main.py.

05:07.920 --> 05:12.920
In fact, I don't even want you to care that much about the code that's in the other files.

05:13.320 --> 05:19.040
It has class definitions and a whole bunch of other things that we're going to learn about in the next

05:19.040 --> 05:19.640
lesson.

05:19.800 --> 05:26.080
But for now, I want you to treat it as if it is an external library, which you're just going to use

05:26.680 --> 05:29.160
at the very beginning of the main.py file.

05:29.160 --> 05:35.240
I've already imported all four classes that you're going to be using menu, Menu item, Coffee Maker,

05:35.240 --> 05:36.360
and Money machine.

05:36.920 --> 05:42.480
Now all of these classes are documented in the Coffee Machine documentation website.

05:42.880 --> 05:49.520
All you have to do is head over to this website and read through what each of the classes do.

05:49.560 --> 05:54.360
Some of them have attributes and methods, others just have methods.

05:54.840 --> 06:02.280
So each of these classes have already pre-written code that do a lot of the heavy lifting and all of

06:02.410 --> 06:06.490
the code that we had to write when we wrote the coffee machine code from scratch.

06:06.930 --> 06:13.450
But this time, you're only going to be using these four classes and the objects created from them in

06:13.450 --> 06:16.650
order to achieve exactly the same goals as before.

06:17.250 --> 06:23.330
So while the goals are fresh in your mind from the previous day, you should review the code from the

06:23.330 --> 06:30.090
previous day and then have a read of the documentation and see how you would implement exactly the same

06:30.090 --> 06:35.530
project, but this time using only the objects created from these classes.

06:35.970 --> 06:40.650
You'll need to spend some time on this, because you'll need to think through how to create objects

06:40.650 --> 06:47.090
from these blueprint classes, and then how to use the objects, how to call the methods and the logic

06:47.090 --> 06:49.170
that's required to put everything together.

06:49.770 --> 06:50.570
Pause the video.

06:50.570 --> 06:57.010
Now have a think about this problem and try to make the coffee machine do exactly the same, and have

06:57.010 --> 07:02.450
all the same functionality as the coffee machine that you created in yesterday's project.
