1
00:00:01,160 --> 00:00:02,500
Hello again, everyone.

2
00:00:02,860 --> 00:00:09,850
So we've been talking a lot about TypeScript, right, so it's why don't we get into something else

3
00:00:09,850 --> 00:00:11,800
called inheritance?

4
00:00:13,270 --> 00:00:21,280
So, as the name suggests, inheritance is the name of the transferred genetic characteristics.

5
00:00:22,670 --> 00:00:28,880
So I'll try to put it into context here and explain it briefly with an example, let's say that there

6
00:00:28,910 --> 00:00:35,340
are employees working in a particular workplace and the customers who shop here.

7
00:00:35,990 --> 00:00:41,210
So what customers and employees have in common is, well, they are a person.

8
00:00:42,940 --> 00:00:45,710
And a person has different features.

9
00:00:46,660 --> 00:00:53,710
So here we are creating a class where we can define common characteristics of people, so we create

10
00:00:53,710 --> 00:01:00,250
a new class for different features, but we extend this new class to the first class.

11
00:01:01,360 --> 00:01:04,480
Thus, we can use the first class features.

12
00:01:06,280 --> 00:01:11,860
So as we will see in practice, I'm first creating a person class in here, I'm.

13
00:01:16,940 --> 00:01:19,190
Writing a simple save method.

14
00:01:26,370 --> 00:01:31,150
Then I'll create a customer class and extend the person class.

15
00:01:31,320 --> 00:01:31,860
You follow.

16
00:01:39,440 --> 00:01:45,050
So that way, the customer class now has the features of this original class.

17
00:01:46,310 --> 00:01:49,580
So here again, I'll add a simple method.

18
00:01:53,380 --> 00:01:56,460
Now, I can create the employee class in the same way.

19
00:02:10,550 --> 00:02:19,490
All right, so we've created our classes, so now it's time to create a new object from each of these

20
00:02:19,490 --> 00:02:20,190
classes.

21
00:02:21,380 --> 00:02:26,300
So first I create an object from the person class and.

22
00:02:32,590 --> 00:02:38,620
Look here, when I put a dot behind the name, I can use the save method.

23
00:02:40,690 --> 00:02:42,640
Now, let's do the same to the customer class.

24
00:02:48,650 --> 00:02:56,610
And now, look, I can use two methods, both in the person class and in the customer class.

25
00:02:57,420 --> 00:02:59,480
Whoa, how can you do that?

26
00:03:00,020 --> 00:03:08,630
Well, we've stated that we can use its properties and methods by extending this class person.

27
00:03:08,630 --> 00:03:14,540
Class features were transferred to the customer class thanks to that the inheritance.

28
00:03:16,460 --> 00:03:20,300
OK, so now when we do the same operations in the third class.

29
00:03:26,360 --> 00:03:32,750
We can use these two methods again, both the methods specific to the class and the method that we will

30
00:03:32,750 --> 00:03:33,680
use in common.

31
00:03:35,080 --> 00:03:40,510
So as you can see, when we create a structure with common features, we do not have to write the same

32
00:03:40,510 --> 00:03:46,080
features on the time we collect common features in one classroom.

33
00:03:47,620 --> 00:03:55,660
Special features in other classes as our work becomes a lot easier when there's any change in the code

34
00:03:55,660 --> 00:03:56,080
editing.

35
00:03:58,250 --> 00:04:05,900
It's now before we finish up here, I do want to briefly introduce you to the idea of private and public

36
00:04:05,900 --> 00:04:13,910
access and how do we actually define it by a whole lot better if we continue on the first car that we

37
00:04:14,270 --> 00:04:15,680
wrote in a class.

38
00:04:16,790 --> 00:04:17,300
All right.

39
00:04:17,300 --> 00:04:22,040
So now, my friends, all the variables we've defined here are public just by default.

40
00:04:25,060 --> 00:04:28,210
And that's just so that we don't have to write public every time.

41
00:04:29,670 --> 00:04:31,290
So what a variable is public?

42
00:04:32,040 --> 00:04:38,550
Well, just as it implies, we're allowed to access that variable from pretty much anywhere.

43
00:04:39,870 --> 00:04:47,700
But if I come in here and write private and yeah, we'll make this very private now, see how we can't

44
00:04:47,700 --> 00:04:49,770
show this very well outside of this class.

45
00:04:55,080 --> 00:04:59,070
However, we can still use it inside the glass.

46
00:05:00,450 --> 00:05:04,800
So here we can only use a variable in that class when we make it private.

47
00:05:05,730 --> 00:05:06,120
All right.

48
00:05:07,730 --> 00:05:12,650
Let's have a look and see what happens when we use a private variable in the person class.

49
00:05:18,210 --> 00:05:20,160
So I'm using a private variable here.

50
00:05:20,400 --> 00:05:23,520
Well, I can use this variable in the customer class.

51
00:05:25,220 --> 00:05:32,210
No, I can't, because, as we said, this variable can only be used within the class in which it is

52
00:05:32,210 --> 00:05:32,900
defined.

53
00:05:33,710 --> 00:05:37,460
So if we define this variable as protected here.

54
00:05:41,970 --> 00:05:43,560
We can now do what we want.

55
00:05:45,290 --> 00:05:54,350
So protected access is pretty much the same logic as private, however, as you can see, it can be

56
00:05:54,350 --> 00:05:56,960
used in inheritance classes.

57
00:06:01,650 --> 00:06:07,470
We won't be able to use this variable outside as a public variable, you follow.

58
00:06:09,990 --> 00:06:15,090
All right, well, let me ask you this, how can we use a private variable outside the class?

59
00:06:16,440 --> 00:06:18,290
Well, I'm glad you bring that up.

60
00:06:19,540 --> 00:06:23,450
Because we've got to talk about getter and setter methods.

61
00:06:24,610 --> 00:06:26,800
All right, so let's have a look at the usage now.

62
00:06:27,790 --> 00:06:34,060
So I'm defining a private variable here and I define the get method that will return this variable.

63
00:06:46,600 --> 00:06:50,200
Then I write the set method that takes this variable.

64
00:07:07,390 --> 00:07:11,740
And now I give a value to this variable outside of this class.

65
00:07:15,220 --> 00:07:21,510
Now we can run these codes and see and here we can see the value that we return.

66
00:07:22,770 --> 00:07:29,400
So by creating the getting set methods of a private variable, we were able to use these methods outside

67
00:07:29,400 --> 00:07:30,130
of the class.

68
00:07:31,140 --> 00:07:31,860
What do you think?

69
00:07:32,820 --> 00:07:35,990
So sure enough, my friends, indeed this classroom is enough.

70
00:07:36,780 --> 00:07:39,190
So in our next lesson, we're going to talk about interface.

71
00:07:39,990 --> 00:07:40,680
I'll see you then.

72
00:07:41,280 --> 00:07:42,000
Bye for now.
