1
00:00:05,310 --> 00:00:09,330
Welcome back, everyone, to this series of lectures where we're going to be discussing the details

2
00:00:09,600 --> 00:00:14,790
of object oriented programming and part one, we're just going to have a slide based overview of the

3
00:00:14,790 --> 00:00:15,750
syntax structure.

4
00:00:17,280 --> 00:00:23,040
So Opie, or object oriented programming allows programmers to create their own objects to have methods

5
00:00:23,040 --> 00:00:23,850
and attributes.

6
00:00:24,270 --> 00:00:30,540
Recall that after we defined a string or list or dictionary or other data type objects in Python, you

7
00:00:30,540 --> 00:00:34,560
were actually able to call methods offer them with the DOP method name syntax.

8
00:00:35,700 --> 00:00:41,850
And these methods act as functions that use information about the object to return results or change

9
00:00:41,850 --> 00:00:42,780
the current object.

10
00:00:43,050 --> 00:00:49,200
For example, this includes a pending an item to a list or counting the occurrences of an element and

11
00:00:49,200 --> 00:00:49,650
a tuple.

12
00:00:51,090 --> 00:00:54,410
OPI allows users to create than their own objects.

13
00:00:54,800 --> 00:00:58,280
The syntax format, however, is often confusing when it's first encountered.

14
00:00:58,670 --> 00:01:02,300
And also, if you're a beginner in Python, you've only used functions so far.

15
00:01:02,600 --> 00:01:08,690
Sometimes it's a little confusing of why it's actually useful to define things as a class in an object.

16
00:01:09,110 --> 00:01:15,190
But in general, object oriented programming allows us to create code that is repeatable and organized.

17
00:01:15,230 --> 00:01:20,210
And more importantly, it's a feature that Django uses quite often, so we do need to understand it.

18
00:01:21,940 --> 00:01:27,280
For much larger scripts of Python code, functions by themselves usually are enough for organization

19
00:01:27,280 --> 00:01:33,550
and repeatability, and commonly repeated tasks and objects can be the of up to create code that is

20
00:01:33,550 --> 00:01:35,020
more usable and readable.

21
00:01:35,200 --> 00:01:38,080
So let's check out the general syntax with a simple example.

22
00:01:39,480 --> 00:01:45,900
So here I have a very simple example of a object oriented programming approach to creating your own

23
00:01:45,900 --> 00:01:47,520
object using class.

24
00:01:47,820 --> 00:01:51,270
So let's go through the main parts of this actual code.

25
00:01:52,530 --> 00:01:58,560
So at the top, in a similar fashion to the way you use the ADF keyword to define a function, you use

26
00:01:58,560 --> 00:02:03,120
the class keyword to define a class or object in Python.

27
00:02:03,480 --> 00:02:08,639
And notice by convention classes use camel case instead of a snake case.

28
00:02:08,820 --> 00:02:13,140
That way, when you're actually calling them in your code, you can tell whether using a function or

29
00:02:13,140 --> 00:02:13,710
a class.

30
00:02:14,880 --> 00:02:21,480
Then there is the in it call, which is the instantiation or initialization call for the actual class.

31
00:02:21,960 --> 00:02:28,380
This is going to help define what parameters or arguments you need to actually pass into the class when

32
00:02:28,380 --> 00:02:32,670
you create a new instance of the class and notice the actual syntax here.

33
00:02:33,450 --> 00:02:38,130
You're going to end up actually passing in parameters and then you're going to use what's known as the

34
00:02:38,130 --> 00:02:42,870
self keyword to assign them to that particular instance of the class.

35
00:02:43,770 --> 00:02:50,100
So here what we're saying is we're passing in some value for parameter two, and then I'm assigning

36
00:02:50,310 --> 00:02:57,540
that parameter to the actual class by saying self-report parameter to essentially linking it to that

37
00:02:57,540 --> 00:02:59,550
particular instance of the class.

38
00:02:59,880 --> 00:03:06,360
So Param two is what the user passes in and self that Param two is, then how we define it and link

39
00:03:06,360 --> 00:03:08,640
it to an instance of the actual class.

40
00:03:10,200 --> 00:03:13,440
And that after that, we can define as many methods as we want.

41
00:03:13,800 --> 00:03:20,460
So these look a lot like functions, but they're inside the actual class call and we can see that the

42
00:03:20,460 --> 00:03:22,950
functions can perform any sort of action they want.

43
00:03:23,160 --> 00:03:25,020
They can also take in their own parameters.

44
00:03:25,290 --> 00:03:27,690
Here we have a very simple method call.

45
00:03:28,020 --> 00:03:32,730
And when we actually have these inside the classes, we won't really be calling them functions.

46
00:03:32,940 --> 00:03:37,620
Instead, we'll call them methods in the class or the act on the class.

47
00:03:37,980 --> 00:03:39,240
Here, this one's really simple.

48
00:03:39,570 --> 00:03:42,420
It just is going to print out parameter one.

49
00:03:42,840 --> 00:03:49,560
You will also notice that it takes in the self keyword argument that lets Python know that this is a

50
00:03:49,560 --> 00:03:56,670
method that can use information of the instance of the class, allowing it to actually call self-taught

51
00:03:56,670 --> 00:03:57,390
param one.

52
00:03:57,810 --> 00:03:59,970
In this case, it's actually just printing it out.

53
00:04:01,690 --> 00:04:05,770
So what we're going to do in the next lecture is actually explore object oriented programming and a

54
00:04:05,770 --> 00:04:10,060
lot more detail of code, and we'll start building out some very basic examples.

55
00:04:10,300 --> 00:04:15,910
And then we're going to add more and more topics like inheritance and special methods later on in future

56
00:04:15,910 --> 00:04:16,390
lectures.

57
00:04:16,779 --> 00:04:21,760
OK, I'll see you at the next lecture, or we begin actually cutting out our first O.P. classes.

