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