Hello again, everyone.
So in this lesson, we'll talk about the class structure, in fact, when we look at JavaScript after
S5 and ESX, it offers as well quite a great object oriented logic, like in Java or C Sharp.
So this structure's become even stronger with TypeScript.
So I'll start briefly with what class is and then I'll show you how to use it.
Class is actually a structure that we can call object.
Class can be briefly summarized as follows, but I'll give you an example, so.
If we're talking about a car.
We can talk about features, right, such as a brand of color, your manufacturer, model of the car
or whatever, but also with this car we can go from place to place and gain in functionality.
So in other words, classes are structures that contain both features and functionality.
In fact, one of the best features of the class structure will bring to us is the ability to make regular
software and to make sustainable software as well, because when we use a class structure, when there's
a feature that we want to change just by making changes in one place, we can effect this feature that
we wherever we use it.
So, yeah, we can start writing now, now to use this structure will use the class keyword and then
write the name and class names, always start with a capital letter.
Got to be careful about that.
Now let's prepare.
Yeah, so this example that I just mentioned, so the class name is and I define properties in curly
brackets.
Such as brand model color.
Year of manufacture.
So now we've written property so we can assign properties using constructor.
So, all right, constructor's and write properties that it can take as parameters, and I'm saying
this.
I'm assigning these properties.
All right, cool of.
So we have now to find properties and constructor's in the class.
Now, let's add a method here that prints the production here, the council car.
So as you can see, we can use this feature in this method.
So why are we now create a new object from this class, so we use the new keyword for this?
So look, when I write the class name here, it already shows the values.
So this object that we created has all the features and methods in this class.
All right, so let's write the features in order here.
And look, when I want to print this object to the console log and look what I want to print this object
in the console log after the name of the object, I'm putting a dot.
And now we can see all the properties and methods in the class.
So I can access the features of this class whenever I want by creating a new object.
And we can define a second object for a different car here and here, we'll use different parameters.
And when we print this second object so long, it will print these properties so we create a single
class and by creating many objects from this class, we can use the same properties with different values.
So if we want to add or delete one more of the features here, one or more, I might say, all we need
to do is make changes within the class.
All right, so that makes quick work, it's also very easy, way more organized, because we don't have
to make changes in every single object.
All right, so that's the class logic, I hope you got a good idea of how to use it, so I want to see
in the next lesson.
Bye for now.