0
1
00:00:00,221 --> 00:00:06,401
So back to our vehicle here as
you can see since the brand is
1

2
00:00:06,401 --> 00:00:11,201
read only we cannot update it
from inside of our class. But
2

3
00:00:11,201 --> 00:00:14,001
we did that because outside of
the class we don't want to be
3

4
00:00:14,001 --> 00:00:21,541
able to do something like this.
Honda.brand equal Toyota
4

5
00:00:21,541 --> 00:00:25,581
okay and that's that's working
okay we we cannot do it but
5

6
00:00:25,581 --> 00:00:29,701
this is problematic so what you
can do instead of using read
6

7
00:00:29,701 --> 00:00:34,261
only you could use the keyword
for example private means
7

8
00:00:34,261 --> 00:00:39,621
basically this variable is now
completely managed by the class
8

9
00:00:39,621 --> 00:00:46,261
only and cannot be updated or
accessed in read or in write
9

10
00:00:46,261 --> 00:00:49,781
outside of the class so now
you're going to notice that if
10

11
00:00:49,781 --> 00:00:53,221
I do honda dot, well you cannot
see anymore brand it's only
11

12
00:00:53,221 --> 00:00:56,881
private you cannot see it from
outside okay so it appear
12

13
00:00:56,881 --> 00:01:02,081
completely from the object but
if you're inside your class for
13

14
00:01:02,081 --> 00:01:05,761
example here as you can see I
still have brand and speed okay
14

15
00:01:05,761 --> 00:01:10,161
I can access all of that so the
private keyword is used when
15

16
00:01:10,161 --> 00:01:14,081
you want to use and manage a
variable or function or
16

17
00:01:14,081 --> 00:01:18,961
anything on the inside the
class okay but you also have
17

18
00:01:18,961 --> 00:01:23,361
the keyword public okay so by
default everything is public so
18

19
00:01:23,361 --> 00:01:25,841
when it's public it means that
you can access it from the
19

20
00:01:25,841 --> 00:01:31,501
inside and from the outside so
if I go so if I go honda dot as
20

21
00:01:31,501 --> 00:01:34,941
you can see brand is here okay
but be careful because
21

22
00:01:34,941 --> 00:01:38,301
something that is public can be
updated and that is pretty
22

23
00:01:38,301 --> 00:01:42,301
dangerous okay we want to only
be able to update it through
23

24
00:01:42,301 --> 00:01:48,621
set brand so it will be way
better to use private on brand
24

25
00:01:48,621 --> 00:01:52,701
now I cannot update brand but
set brand is public by default
25

26
00:01:52,701 --> 00:01:56,701
okay I can write it if you want
public and this way the only
26

27
00:01:56,701 --> 00:02:01,441
way to update honda is to do
a set brand and now I can do
27

28
00:02:01,441 --> 00:02:13,141
something like this. And I can
log my brand. Oh obviously I
28

29
00:02:13,141 --> 00:02:16,581
can't okay I cannot read my
brand so if you want to read
29

30
00:02:16,581 --> 00:02:20,181
your brand then you will have
to create a function that is
30

31
00:02:20,181 --> 00:02:27,221
public for example get brand
like this and just return this
31

32
00:02:27,221 --> 00:02:30,501
dot brand like this and so
obviously I'm going to say that
32

33
00:02:30,501 --> 00:02:36,461
this is returning a string and
instead of doing that, I'm
33

34
00:02:36,461 --> 00:02:44,101
going to do a get brand. And
yes it's working so that's the
34

35
00:02:44,101 --> 00:02:46,981
difference between private and
public okay private it's only
35

36
00:02:46,981 --> 00:02:51,781
for the class to manage and
public anyone can manage it but
36

37
00:02:51,781 --> 00:02:55,541
you also have static I don't
know if you know this one so
37

38
00:02:55,541 --> 00:02:58,101
static
38

39
00:02:58,721 --> 00:03:05,701
For example, color, okay, that
could be a string as well. So
39

40
00:03:05,701 --> 00:03:10,421
static means that you can use
this variable modify it read
40

41
00:03:10,421 --> 00:03:14,661
from it without even having to
create an instance of the glass
41

42
00:03:14,661 --> 00:03:19,061
okay so even without having to
do a new something and store it
42

43
00:03:19,061 --> 00:03:23,701
somewhere okay so it means that
basically I could for example
43

44
00:03:23,701 --> 00:03:26,741
set a default value for my
color I don't know black like
44

45
00:03:26,741 --> 00:03:32,581
this and now even if I don't
have any vehicle at all I can
45

46
00:03:32,581 --> 00:03:38,641
just do this vehicle dot color
and as you can see that's the
46

47
00:03:38,641 --> 00:03:43,961
only one that I can access okay
color because it's static and
47

48
00:03:43,961 --> 00:03:47,921
as you can see yeah I can
access the color so you don't
48

49
00:03:47,921 --> 00:03:52,481
even need to to create an
instance out of it okay so it's
49

50
00:03:52,481 --> 00:03:57,041
sometimes useful for example if
you create a function like I I
50

51
00:03:57,041 --> 00:04:01,281
often do when I create an API
so for example I create
51

52
00:04:01,281 --> 00:04:08,821
something like this a class for
example vehicle API and then
52

53
00:04:08,821 --> 00:04:11,141
inside I'm going to create a
static function that is going
53

54
00:04:11,141 --> 00:04:17,621
to be fetch all and then inside
I'm going to do an asynchronous
54

55
00:04:17,621 --> 00:04:22,161
request for example. Oh you
don't have to write function
55

56
00:04:22,161 --> 00:04:27,281
sorry and well I don't want to
have to do something like this
56

57
00:04:27,281 --> 00:04:30,321
anytime I want to use my API
you know I don't want to do
57

58
00:04:30,321 --> 00:04:38,321
vehicle API equal new vehicle
API etcetera etcetera and then
58

59
00:04:38,321 --> 00:04:43,281
finally do a vehicle API dot
fetchAll okay I want to be
59

60
00:04:43,281 --> 00:04:49,361
able to just use my vehicle API
like this instantly okay so
60

61
00:04:49,361 --> 00:04:54,761
that's an example of when could
use static. Alright so that is
61

62
00:04:54,761 --> 00:04:58,121
pretty much about the accessor
so private, public and static.
62

63
00:04:58,121 --> 00:05:00,681
There is another one that is
predicted but we will see this
63

64
00:05:00,681 --> 00:05:03,961
one later in the course. All
right so see you in the next
64

65
00:05:03,961 --> 00:05:07,161
one. I hope it was clear.
