0
1
00:00:00,221 --> 00:00:03,601
Alright so in this video we're
going to talk about classes so
1

2
00:00:03,601 --> 00:00:06,961
I'm going to show you how to
type a class and you're going
2

3
00:00:06,961 --> 00:00:10,721
to notice that it's actually
pretty straight forward if you
3

4
00:00:10,721 --> 00:00:14,721
already know how to type
functions we're going to create
4

5
00:00:14,721 --> 00:00:20,081
a new class that is going to be
a vehicle like this in this
5

6
00:00:20,081 --> 00:00:23,761
vehicle we will have two
variables, will have the speed
6

7
00:00:23,761 --> 00:00:28,321
that is going to be a number
and a brand that is going to be
7

8
00:00:28,321 --> 00:00:33,041
a string the we're going to
create a constructor to be able
8

9
00:00:33,041 --> 00:00:39,201
to send values to our vehicle
so constructor like this and we
9

10
00:00:39,201 --> 00:00:43,281
are going to receive a speed
that is going to be a number
10

11
00:00:43,281 --> 00:00:50,501
and a brand that is going to be
a string and then we are going
11

12
00:00:50,501 --> 00:00:53,781
to fill our variables with the
values that we have here so I'm
12

13
00:00:53,781 --> 00:01:03,161
going to do this speed receive
speed, and same with the brand.
13

14
00:01:03,721 --> 00:01:08,221
Now I can create my first
vehicle so let's say I have a
14

15
00:01:08,221 --> 00:01:13,501
Honda here that is going to be
a new vehicle and I'm going to
15

16
00:01:13,501 --> 00:01:17,821
send my speed and my brand so
for example 200 my brand is
16

17
00:01:17,821 --> 00:01:27,281
going to be Honda like this now
I can log my own data so for
17

18
00:01:27,281 --> 00:01:31,281
example I can log my brand like
this and as you can see no
18

19
00:01:31,281 --> 00:01:37,821
problem with that, now if I want,
nothing prevent me from
19

20
00:01:37,821 --> 00:01:42,141
updating the content of my
class directly from here, so I
20

21
00:01:42,141 --> 00:01:48,621
could do on the dot brand
receive something else for
21

22
00:01:48,621 --> 00:01:54,221
example Tesla but this is
pretty dangerous okay because
22

23
00:01:54,221 --> 00:02:00,101
now if I log it for example Honda dot
brand as you can see
23

24
00:02:00,101 --> 00:02:05,781
it's been updated and maybe I
want to make sure that when my
24

25
00:02:05,781 --> 00:02:09,781
brand is updated I want to make
sure that it has a correct case
25

26
00:02:09,781 --> 00:02:12,981
okay it start with an upper
case and the rest is in lower
26

27
00:02:12,981 --> 00:02:15,861
case for example but maybe I
want to make sure that when I
27

28
00:02:15,861 --> 00:02:21,621
send a brand it has to be in
pascal case for example like this okay
28

29
00:02:21,621 --> 00:02:25,221
with an upper case at the
beginning so by doing that I'm
29

30
00:02:25,221 --> 00:02:28,741
not able to do any check so
what I would do is I would
30

31
00:02:28,741 --> 00:02:32,841
create for example a set brand
to manage myself how I update
31

32
00:02:32,841 --> 00:02:35,641
the brand right so I would
receive a brand that would be a
32

33
00:02:35,641 --> 00:02:40,361
string and this would return
absolutely nothing okay so I
33

34
00:02:40,361 --> 00:02:46,481
would set void and I would just
take my brand and send inside
34

35
00:02:46,481 --> 00:02:52,861
the new brand so I'm going to
call that new brand the new
35

36
00:02:52,861 --> 00:02:58,061
brand I'm just going to take
the first character and put it
36

37
00:02:58,061 --> 00:03:02,941
in upper case and I'm going to
add the rest of the word in
37

38
00:03:02,941 --> 00:03:07,741
lowercase so I'm going to use
new brand dot slice and I'm
38

39
00:03:07,741 --> 00:03:10,381
going to slice I'm not going to
take the first character only
39

40
00:03:10,381 --> 00:03:14,541
the second one and I'm going to
go until the end of the word so
40

41
00:03:14,541 --> 00:03:22,721
new brand. lens I'm going to
put that in lowercase like
41

42
00:03:22,721 --> 00:03:29,141
this. So now instead of doing
that what I could do is on
42

43
00:03:29,141 --> 00:03:35,601
that. said brand and send for
example Tesla and yup, it's
43

44
00:03:35,601 --> 00:03:38,801
correctly formatted but I'm
still able to do that so I
44

45
00:03:38,801 --> 00:03:43,041
could for example say that
specifically I want this to be
45

46
00:03:43,041 --> 00:03:48,721
read only and now I cannot
write anymore in my vehicle
46

47
00:03:48,721 --> 00:03:52,241
from here okay but you're going
to notice that I'm also
47

48
00:03:52,241 --> 00:03:56,081
affected here okay I cannot
update my brand anymore because
48

49
00:03:56,081 --> 00:03:59,921
this is read only so this is
problematic because I want to
49

50
00:03:59,921 --> 00:04:05,761
be able to modify my brand from
my class but not from outside.
50

51
00:04:05,761 --> 00:04:09,041
Okay? So this is problematic.
So as you can see obviously
51

52
00:04:09,041 --> 00:04:12,401
it's still working okay here
but as a developer I know that
52

53
00:04:12,401 --> 00:04:17,041
there is an error here, okay? I
shouldn't be doing that. So in
53

54
00:04:17,041 --> 00:04:21,041
the next day we're going to see
the different access level that
54

55
00:04:21,041 --> 00:04:24,401
you can set on a variable. So
private, public, maybe you have
55

56
00:04:24,401 --> 00:04:28,401
heard already of this accessor.
So we're going to see that in
56

57
00:04:28,401 --> 00:04:30,881
the next video to be able to
have different level of
57

58
00:04:30,881 --> 00:04:34,881
privilege inside a class and
outside. Okay? So see you on
58

59
00:04:34,881 --> 00:04:37,518
the next one.
