Okay so in this video we're going to talk about object 1
oriented programming. Technically I assume that you 2
already know what this is but I just want to give you a quick 3
refresher because we're going to do a lot of classes, 4
objects, inheritance, things like this so I think that a 5
quick refresher can help. Okay? So this will just be a quick 6
refresher on the general concept of object oriented 7
programming. So just so you know but before objected 8
oriented programming I'm going to say OOP from now. Um there 9
was the procedural programming and basically your 10
program was just made out of a lot of functions, and that's 11
it just functions functions functions and the problem is as 12
it grow it gets hard to maintain okay and you can 13
rapidly end up having a lot of functions that call other 14
functions and you will end up having a lot of 15
interdependencies and you can end up in what we call an anti 16
pattern that is the spaghetti code , so not cool and 17
basically that is what the OOP is going to try to solve okay 18
so the OOP is not going to make you code faster or something 19
like this it's going just going to make it easier to maintain 20
easier to manipulate because it's more a human approach 21
because we are going to create objects like for example a car 22
it's easier to to to visualize to picture what a car is and 23
when you think a car you may think okay that's something 24
that has four wheels that can move and that could be 25
translated into a class and an object and that's what the OOP 26
is about. So for example a program is now going to be made 27
out of class methods and properties. So for example a 28
class would be what we call an object in general so it's a 29
class and a class contains methods and properties so 30
methods that aren't just basically functions that runs 31
on code and that can access the properties of the class and use 32
them if they want. So properties just basically a 33
value okay it can be a number a string an array or something 34
more complex and you can have a lot of classes in your program 35
and then can communicate between each other or just 36
communicate with themselves only okay and you can use them 37
as the like they were a single piece of information so for 38
example the most typical example is a car like I told 39
you and a car could have several methods like start accelerate 40
decelerate stop and so on and you could have some properties 41
inside for example a color for the car or a model okay for the 42
car now in term of code in general okay it's not specific 43
to type script but in general that is the basic structure of 44
a class okay a class just have a name and then inside you're 45
going to have all your attributes in general at the 46
top and below that you're going to have all your methods all 47
your the function of the class okay now you may think okay 48
cool I have a class I have a car so the class is kind of the 49
recipe for how the object is going to work how the car is 50
going to work but maybe you want to create an actual car 51
build it okay and we call that create an instance out of a 52
class so for example let's say we have this kind of model for 53
the car we have so this class okay this recipe and as you can 54
see here I have set a car and a model inside my class so a car 55
will always be blue and it will always be a Tesla for now and 56
if I want to read create this blue Tesla I will have to use 57
the syntax. I will just to use the new keyword and create a 58
car like this. And then I can start the result in a variable. 59
Now inside I really have an instance of the class. I I 60
really have a card they can use. So I can do my car. 61
start or my car.accelerate or I can even access 62
the properties of my class if I want. By calling them by their 63
name. And that's it. So pretty cool but in general you don't 64
really have a car in your program so I'm going to give 65
you a real example maybe you have already used it so for 66
example if you go on in your browser for example on Google 67
you can use an object that is a very famous one and it's a 68
local storage so behind the scene this is a class this is 69
an object that has been instantiated already and you 70
can use it to store information for this very specific website 71
in your browser and so on this object I can use the set item 72
method to store an information for this very specific website 73
and so you have to define a key so that's the first parameter 74
and you can send then a value so for example my value like 75
this and when I'm going to do that it's going to be stored in 76
a browser for this very specific web page so Google. 77
com and the cool thing is that now if I refresh now I can do a 78
local storage.getItem and this time I can send my key the 79
key that I've used previously to retrieve my value and it's 80
always going to even if I refresh my page. Okay? So 81
behind the scene local storage is an actual object, okay? Um 82
and it also have properties, okay? For example .length, it's 83
not a method, it's not a function, but it's going to 84
return value. So that's a class that you are maybe have already 85
used. So let's go back to our class. So now that's cool, we 86
have a blue Tesla, that's nice, but maybe you want a red 87
Mustang okay and so for now well anytime you're going to 88
create a car it's always going to be a blue Tesla so maybe you 89
want when you create your car to be able to send arguments to 90
this class so it will be initialized with all values so 91
to do that you have to use a very specific method of a class 92
that exist for all the classes that you can redefine and so by 93
default it's not going to do anything it's called 94
constructor that is an hidden method of a class by default 95
it's a function that does nothing but you can add things 96
in it for example let's say we have this car model and we want 97
like I told you send a red Mustang to this new car okay 98
when you're doing that you're actually calling the 99
constructor so now in my class here I can actually define a 100
constructor and say that I expect to receive two values 101
for example a car and a model and then I'm going to use for 102
example this color here to fill my car property, and so since 103
they have the same name you can use the this dot keyword to 104
really explicitly tell that you want to target what is owned by 105
the class so this is the color owned by the class okay this is 106
not an external color this is an external color it comes from 107
the outside okay so when you use the this dot keyword you're 108
actually explicitly telling that you want to target 109
something that is owned by the class so you can do this. 110
color this.dot model or even this.start or this.stop 111
anything that is attached to the class. All right? So this 112
means it's in the class. And now if you log myMUstand dot 113
color after initializing it like this you should have "red" 114
returned because now this dot color is equal to red. All 115
right? So that's pretty much it about the object oriented 116
programming. Okay? Uh obviously there are a lot of other thing 117
that we have to talk about like inheritance like abstractions, 118
a lot of other concepts, but actually we're going to use 119
them during the course and I will re explain how they are working 120
so this should help you. All right? So yeah that's pretty 121
much it for this quick refresher. I hope it was clear 122
and see you on the next one.