1
00:00:00,280 --> 00:00:01,830
Another concept within

2
00:00:02,240 --> 00:00:02,349
OOP

3
00:00:03,349 --> 00:00:07,019
is the concept of polymorphism,

4
00:00:07,659 --> 00:00:12,130
which basically translates to same action but different behavior.

5
00:00:12,619 --> 00:00:15,829
The thing about polymorphism is that it's going to allow classes

6
00:00:16,129 --> 00:00:19,559
to have methods with the exact same name

7
00:00:19,909 --> 00:00:22,280
but then behave differently.

8
00:00:22,600 --> 00:00:26,360
So as an example, still dealing with the user class,

9
00:00:26,639 --> 00:00:32,279
we can have different types of users logging in both in a different manner.

10
00:00:32,720 --> 00:00:35,119
So as an example, let's have different roles.

11
00:00:35,130 --> 00:00:37,819
So I'm going to create a class for the regular user

12
00:00:37,950 --> 00:00:39,810
and then a class for the admin user

13
00:00:39,970 --> 00:00:43,220
and then they're gonna have unique ways of actually logging in. So

14
00:00:43,340 --> 00:00:48,290
check this out. I'm gonna come in here right now and create class regular

15
00:00:48,880 --> 00:00:49,700
user.

16
00:00:50,599 --> 00:00:51,299
OK?

17
00:00:51,459 --> 00:00:52,299
And now

18
00:00:52,540 --> 00:00:54,409
I am going to define

19
00:00:55,189 --> 00:00:56,330
very simply

20
00:00:56,860 --> 00:00:57,529
the

21
00:00:57,659 --> 00:00:59,139
method log in

22
00:01:00,090 --> 00:01:01,270
and self.

23
00:01:01,599 --> 00:01:05,010
OK. Notice I haven't passed in any attributes whatsoever.

24
00:01:05,040 --> 00:01:07,330
I'm just going straight to the method. OK? So

25
00:01:07,580 --> 00:01:09,110
what I'll do right now is

26
00:01:09,910 --> 00:01:12,580
I am simply going to say print.

27
00:01:14,400 --> 00:01:15,300
Now,

28
00:01:15,650 --> 00:01:20,610
I would just say a regular user has logged

29
00:01:21,819 --> 00:01:22,400
in.

30
00:01:23,739 --> 00:01:24,279
OK?

31
00:01:25,650 --> 00:01:28,879
Now look at this, OK? I'm gonna create another class

32
00:01:29,349 --> 00:01:31,300
and let's call this the admin

33
00:01:31,519 --> 00:01:32,430
user.

34
00:01:33,690 --> 00:01:34,980
OK? Hold on.

35
00:01:35,239 --> 00:01:37,050
And now again, define

36
00:01:37,440 --> 00:01:40,519
and now the exact same method log in

37
00:01:40,819 --> 00:01:42,269
self.

38
00:01:42,419 --> 00:01:43,410
But now

39
00:01:43,639 --> 00:01:46,800
it's gonna be a different print message

40
00:01:46,970 --> 00:01:51,889
because now I'm gonna say admin has logged in

41
00:01:53,269 --> 00:01:54,970
and let me just close this

42
00:01:55,739 --> 00:02:01,209
and there it is. So now for the actual polymorphism, we're gonna make use of it.

43
00:02:01,569 --> 00:02:03,419
Let's assign user

44
00:02:04,000 --> 00:02:08,600
to be equal to regular user. So let's create our first objects in here for

45
00:02:09,100 --> 00:02:10,160
the regular user.

46
00:02:10,288 --> 00:02:13,550
Let's also create an object for the admin user.

47
00:02:13,559 --> 00:02:16,509
And of course, I'll call this one admin equals to

48
00:02:17,259 --> 00:02:18,110
admin

49
00:02:18,449 --> 00:02:19,210
user.

50
00:02:20,119 --> 00:02:20,779
And

51
00:02:21,119 --> 00:02:25,699
it is so we've created objects for the regular user and the admin user,

52
00:02:25,830 --> 00:02:28,740
let's now call them. So I'm gonna say user

53
00:02:29,050 --> 00:02:30,100
dot log in

54
00:02:31,270 --> 00:02:33,020
brackets and now

55
00:02:33,190 --> 00:02:36,240
also admin dot log in

56
00:02:37,369 --> 00:02:41,110
and there you go. So now let us try to run the program

57
00:02:41,369 --> 00:02:42,330
and there it is

58
00:02:42,440 --> 00:02:44,220
regular user has logged in,

59
00:02:44,360 --> 00:02:46,960
admin has logged in.

60
00:02:47,339 --> 00:02:52,460
So this is the concept of polymorphism where you can have two different classes

61
00:02:53,160 --> 00:02:55,179
with the exact same method.

62
00:02:55,490 --> 00:02:59,649
But that method will act in a different manner depending on which particular

63
00:03:00,029 --> 00:03:03,460
object or class object is calling that method.

64
00:03:03,470 --> 00:03:06,559
The method used here obviously is the login method.

65
00:03:06,570 --> 00:03:09,559
It's applicable to both the class regular user

66
00:03:09,699 --> 00:03:11,149
and the class admin user.

67
00:03:11,300 --> 00:03:13,289
But it's gonna behave differently because it,

68
00:03:13,300 --> 00:03:15,440
it's gonna print out a different message

69
00:03:15,550 --> 00:03:19,059
depending on which class object actually logged in.

70
00:03:19,330 --> 00:03:22,830
So that's polymorphism for you. Same action, different behavior.

71
00:03:23,020 --> 00:03:25,470
Thank you for watching the video. I'll see you in the next class.

