1
00:00:00,700 --> 00:00:01,780
Hey, welcome back.

2
00:00:01,960 --> 00:00:07,900
In this video, you're going to learn what inheritance is and how to use it in your programs.

3
00:00:08,290 --> 00:00:12,670
So previously in the previous video, we added this credit card feature.

4
00:00:12,670 --> 00:00:18,940
So now we check if the credit card is validated and then we let the user book the hotel.

5
00:00:18,970 --> 00:00:27,550
Now, sometimes, though, some credit cards have another security layer, so it's not enough to enter

6
00:00:27,550 --> 00:00:33,480
the credit card number and the expiration date, the holder name and the CVC.

7
00:00:33,490 --> 00:00:40,660
But you also need to provide some sort of passwords and sometimes even a username and password through

8
00:00:40,660 --> 00:00:42,910
an additional web page.

9
00:00:43,330 --> 00:00:49,600
However, our program doesn't support those credit cards yet.

10
00:00:49,960 --> 00:00:51,850
So what should we do then?

11
00:00:52,390 --> 00:00:56,850
Should we modify the class credit card?

12
00:00:56,860 --> 00:01:02,140
So maybe add some more methods here or modify by the valid methods?

13
00:01:02,590 --> 00:01:08,590
Well, the answer is no, because when you want to add some new features like we're doing now, we're

14
00:01:08,590 --> 00:01:12,400
adding this new secure credit card feature.

15
00:01:12,400 --> 00:01:17,290
When you want to add more features, you don't want to modify existing classes.

16
00:01:17,290 --> 00:01:21,010
So this is one of the principles of o.P.

17
00:01:21,430 --> 00:01:25,480
What you want to do instead is add more classes.

18
00:01:25,870 --> 00:01:34,360
Of course, it's fine to add methods to a class when you are coding that class, so it was fine to add

19
00:01:34,360 --> 00:01:37,870
a defined pay method in the previous video.

20
00:01:38,170 --> 00:01:42,340
If we wanted to do this in a more real life situation.

21
00:01:42,790 --> 00:01:47,800
But once you have completed the class, once you have completed the feature and then you want to add

22
00:01:47,800 --> 00:01:50,950
more features, then it's good to create new classes.

23
00:01:51,220 --> 00:01:53,140
That's what we're going to do now.

24
00:01:53,140 --> 00:01:59,140
Class secure credit card, right?

25
00:02:00,150 --> 00:02:08,009
Now, the thing is that this secure credit cards would be checked for that username and passwords,

26
00:02:08,009 --> 00:02:14,250
which for them where we have created this CSV file, you can find it attached in the lecture resources.

27
00:02:14,250 --> 00:02:20,820
So we have the cards dot CSV file, which we covered in the previous video, and then we have this additional

28
00:02:20,830 --> 00:02:22,620
CSV data.

29
00:02:22,800 --> 00:02:26,820
So in here we have like the card numbers one, two, three, four.

30
00:02:26,850 --> 00:02:28,800
Actually it's this number.

31
00:02:30,540 --> 00:02:36,330
So that's a number of the cards and that is the password of that court, basically.

32
00:02:36,600 --> 00:02:43,500
So the user will have to enter the password of their card in the program and then we'll check against

33
00:02:43,500 --> 00:02:44,340
these data.

34
00:02:45,030 --> 00:02:53,340
So to check against those data means we need a method that checks the password, but we also need to

35
00:02:53,340 --> 00:02:57,870
validate the expiration holder and CVC values as well.

36
00:02:58,470 --> 00:03:06,540
So what we're talking about here is basically having the same class credit card, but with some extended

37
00:03:06,540 --> 00:03:08,100
capabilities.

38
00:03:08,190 --> 00:03:15,270
This extended capability is the capability to check if the password is correct.

39
00:03:15,720 --> 00:03:25,920
So in that case, we don't want to write that class again like in it and then have define, validate

40
00:03:26,550 --> 00:03:31,910
and then have another define authenticate.

41
00:03:31,920 --> 00:03:35,490
Maybe we don't want to rewrite these methods.

42
00:03:35,490 --> 00:03:42,780
What we do instead is we inherit that credit card class from this class.

43
00:03:43,540 --> 00:03:44,920
To inherit a class.

44
00:03:44,920 --> 00:03:50,770
When you define the class in the first line, you use some parentheses, and then there you enter the

45
00:03:50,770 --> 00:03:55,030
credit card class, the name of the class you want to inherit.

46
00:03:55,700 --> 00:04:04,040
And to now this secure credit card class is known as the child, and this is known as a parent class.

47
00:04:04,040 --> 00:04:06,860
So the parent and the child.

48
00:04:06,860 --> 00:04:16,010
So the child is inheriting all these methods from the parents, but the child will be more advanced

49
00:04:16,160 --> 00:04:20,570
than the parent because the child will have this authenticate method.

50
00:04:20,570 --> 00:04:27,500
In addition, you'll see exactly what I mean when I say the child has inherited these methods.

51
00:04:27,500 --> 00:04:31,160
So first let me implement the authenticate method.

52
00:04:31,160 --> 00:04:35,690
So this again would need access to that card, that security, the CSV file.

53
00:04:35,690 --> 00:04:50,270
So for that we say to F here on top cards, security is equal to pandas that read c v cards underscore

54
00:04:50,300 --> 00:04:57,200
security point C is V and let's load the types as str.

55
00:04:59,740 --> 00:05:11,650
And then we go down here in authenticate and we want to get the passwords from the DF cards security

56
00:05:11,650 --> 00:05:15,340
variable, which is a data frame that lock.

57
00:05:17,090 --> 00:05:22,310
So we get DFF number which should be equal to self.

58
00:05:22,310 --> 00:05:23,150
That number.

59
00:05:23,150 --> 00:05:26,150
I'll explain you what self that number is doing here.

60
00:05:26,480 --> 00:05:32,450
So sell that number and then we extract the password.

61
00:05:32,780 --> 00:05:33,240
Right.

62
00:05:33,290 --> 00:05:35,510
Password is this field.

63
00:05:35,510 --> 00:05:39,110
So we have a number column and the password column as well.

64
00:05:39,110 --> 00:05:40,040
Two columns.

65
00:05:40,670 --> 00:05:41,720
So that is the number.

66
00:05:41,720 --> 00:05:42,260
Column.

67
00:05:42,260 --> 00:05:43,550
That is the password column.

68
00:05:43,550 --> 00:05:53,930
So we are saying oh give me the password value where the value of this number column is equal to that.

69
00:05:54,140 --> 00:05:55,550
Now what is that?

70
00:05:55,550 --> 00:05:58,220
Well, that is this here.

71
00:05:58,890 --> 00:06:05,370
So basically, as I told you, this child class inherits everything from this class.

72
00:06:05,370 --> 00:06:08,520
And that is the first example of inheriting.

73
00:06:08,880 --> 00:06:12,120
And you'll see that this class also inherits the methods.

74
00:06:12,120 --> 00:06:17,730
So not only the instance variables such as this self, that number, but also the methods.

75
00:06:18,150 --> 00:06:20,550
And let's add squeeze here.

76
00:06:22,150 --> 00:06:27,010
To get the actual value for the passwords and not just the series.

77
00:06:27,160 --> 00:06:38,110
Then we say if password is equal to given passwords, which is going to be a parameter of the authenticate

78
00:06:38,110 --> 00:06:40,900
method given password.

79
00:06:43,780 --> 00:06:44,290
Return.

80
00:06:44,290 --> 00:06:44,950
True.

81
00:06:45,160 --> 00:06:48,220
Sorry, this has to be an equal comparison.

82
00:06:48,220 --> 00:06:49,060
Operator.

83
00:06:51,130 --> 00:06:53,590
Else return false.

84
00:06:53,620 --> 00:06:57,160
Although you can omit this and it's it will still work.

85
00:07:00,800 --> 00:07:11,390
So then we can go down here and instead of using the credit card class we use, we use the C, Q credit

86
00:07:11,390 --> 00:07:13,100
card class.

87
00:07:13,550 --> 00:07:14,280
Right?

88
00:07:14,300 --> 00:07:21,290
So now credit card, this variable holds an instance of secure credit cards.

89
00:07:21,290 --> 00:07:29,930
And this secure credit card takes the number as an argument, although we don't have an init methods

90
00:07:29,930 --> 00:07:32,660
here, which gets a number as an argument.

91
00:07:32,690 --> 00:07:36,740
We do have an init method in the parent class.

92
00:07:36,860 --> 00:07:43,460
And since this secure credit card class inherits everything from the credit card class.

93
00:07:46,830 --> 00:07:48,060
That means.

94
00:07:49,280 --> 00:07:51,800
It's also inherits that in its methods.

95
00:07:51,800 --> 00:07:57,680
So we can provide all the parameters that the init method takes in the credit card class.

96
00:07:57,710 --> 00:07:58,310
Right.

97
00:07:58,550 --> 00:08:04,760
And then the validate method also can be applied to this secure credit card instance.

98
00:08:04,760 --> 00:08:05,360
Right.

99
00:08:05,360 --> 00:08:07,730
Which is represented by this variable.

100
00:08:07,730 --> 00:08:10,100
So the validate method is also inherited.

101
00:08:10,100 --> 00:08:14,630
Therefore we can pass the methods and all its arguments.

102
00:08:14,660 --> 00:08:17,480
So everything else remains the same.

103
00:08:19,290 --> 00:08:24,690
And of course, we also need to add the authenticate method call here.

104
00:08:25,350 --> 00:08:36,659
So first we validate the codes and then we add another conditional layer if credit codes that authenticate.

105
00:08:38,419 --> 00:08:41,090
And then we end we enter the passwords.

106
00:08:41,480 --> 00:08:43,610
Actually, it's given passwords.

107
00:08:43,610 --> 00:08:48,410
That's the name of the parameter.

108
00:08:50,260 --> 00:09:00,130
So that is equal to the password, which you can get it from the user using like a variable here with

109
00:09:00,130 --> 00:09:01,120
an input function.

110
00:09:01,120 --> 00:09:07,300
Or if you want to keep it simple, you can just provide the passwords which is here my pass.

111
00:09:07,300 --> 00:09:10,540
So write my pass here as a string.

112
00:09:12,040 --> 00:09:22,660
And then if that turns true, which is the case with the password is equal to the given password, then

113
00:09:22,660 --> 00:09:31,960
we want to book the hotel, ask the user for their name, create a reservation ticket instance, print

114
00:09:31,960 --> 00:09:33,940
out the reservation ticket

115
00:09:36,250 --> 00:09:42,010
and perhaps add a new LS statement here ls print.

116
00:09:43,330 --> 00:09:47,770
Credit card authentication failed.

117
00:09:48,850 --> 00:09:52,060
So that else statement is part of this.

118
00:09:52,060 --> 00:09:56,770
If conditional block and this one here belongs to that.

119
00:09:56,770 --> 00:09:59,470
So be careful with the indentation level.

120
00:09:59,470 --> 00:10:00,070
Right.

121
00:10:01,510 --> 00:10:04,150
And that is paired with that.

122
00:10:05,290 --> 00:10:08,890
So we can run the program now run main.

123
00:10:11,020 --> 00:10:12,160
Perhaps an error.

124
00:10:12,250 --> 00:10:12,710
Yep.

125
00:10:12,940 --> 00:10:15,550
Directory cards security not found.

126
00:10:16,090 --> 00:10:17,890
So I had.

127
00:10:19,010 --> 00:10:19,870
My typo here.

128
00:10:19,880 --> 00:10:22,310
Card security does CSC.

129
00:10:23,330 --> 00:10:26,360
It's not cards, it's card security.

130
00:10:26,720 --> 00:10:28,100
So let's run again.

131
00:10:31,420 --> 00:10:33,370
And to the idea of the hotel.

132
00:10:33,550 --> 00:10:36,490
Now all the hotels have no availability.

133
00:10:36,490 --> 00:10:40,300
So we're going to get hotel is not free.

134
00:10:40,300 --> 00:10:48,970
So let's change one of these to yes save the hotels that see the file run again.

135
00:10:50,620 --> 00:10:52,030
188.

136
00:10:53,920 --> 00:10:54,730
Another error.

137
00:10:54,730 --> 00:10:57,790
Let's see what this is telling us.

138
00:10:57,790 --> 00:11:05,080
So look at the line, which is pointing to your file, not to the other files in our other modules.

139
00:11:05,830 --> 00:11:07,530
So that's our main that's p file.

140
00:11:07,540 --> 00:11:16,240
I click there, it takes me here and this is complaining that number was not found in the data frame.

141
00:11:16,240 --> 00:11:20,200
So a key error is part of PANDAS data frames, errors.

142
00:11:20,200 --> 00:11:25,570
So we take a look at the court security seal we file.

143
00:11:27,060 --> 00:11:31,390
Now here I can see that the column number is actually called number.

144
00:11:31,410 --> 00:11:34,080
So that should be some other issue here.

145
00:11:34,500 --> 00:11:40,690
What I can see is that I didn't use the FS card security here in here, but I use DF.

146
00:11:40,710 --> 00:11:45,000
So DF should be replaced DF card security.

147
00:11:46,350 --> 00:11:46,660
Yeah.

148
00:11:46,680 --> 00:11:47,520
Run again.

149
00:11:48,840 --> 00:11:51,720
188 This hotel.

150
00:11:52,400 --> 00:11:55,020
Press enter into your name, audit.

151
00:11:55,860 --> 00:11:57,960
And yeah, we've got.

152
00:11:59,240 --> 00:12:05,180
The reservation ticket if this given passwords here.

153
00:12:07,190 --> 00:12:11,180
Was not my past, but something else like my past one.

154
00:12:12,270 --> 00:12:14,240
And we run against the code.

155
00:12:14,250 --> 00:12:26,370
So let's change this back to Yes, run main 188 and we're going to get credit card authentication failed.

156
00:12:26,490 --> 00:12:33,450
So the data we have entered in here, which is a password, gave us this problem.

157
00:12:34,760 --> 00:12:39,050
So that's what we expected to have this error so that it's working fine.

158
00:12:39,200 --> 00:12:42,530
And yeah, that is about inheritance.

159
00:12:42,530 --> 00:12:49,790
So inheritance is when you create a new class which inherits from an existing class.

160
00:12:49,790 --> 00:12:53,210
So the new class will have additional methods.

161
00:12:53,210 --> 00:13:00,950
So those additional methods are defined in the new class, but you don't need to define the existing

162
00:13:00,950 --> 00:13:02,960
methods of the parent class.

163
00:13:03,380 --> 00:13:11,210
You just call them just like we did here validate and you also can use.

164
00:13:15,730 --> 00:13:19,090
The variables that are passed to.

165
00:13:21,230 --> 00:13:23,270
The class instance.

166
00:13:23,270 --> 00:13:33,890
So number was part of the credit cards class, but it is also part of secure credit card.

167
00:13:35,210 --> 00:13:36,940
And that's about inheritance.

168
00:13:36,950 --> 00:13:39,290
So thanks a lot for following and I'll see you later.

