OOP with TypeScript: Basics of Classes


English (Auto-generated)

cramming in the typescript. So the thing is in the previous cast we did something and you know, we just created a few variables and we created a function and we utilized the function um we utilized the function inside the class. Sorry. Outside uh we just utilize the function here in this script and we just got the variables inside the function. The problem is nothing of them is connected. But here we really realized in the O B J one that things are connected with the, with this object, the O B J one. This is what we can see here. So then we now able to call the function. The function name is function the full name one. And in the full name one we are calling Oh, BJ one dot my name. Oh BJ one dot father name. So now at least these variables are connected. All these variables has one object and this object name can be anything. This object name can be the name of mind, like Shazia Kamal or this object. Uh this object can be O B G one or a person one or anything else. But now at least the variables are together and these are not variables. Now these are the properties of an object which is the O B J one. But the thing is it is not exactly the object oriented programming yet because we are lacking a very main factor. The blueprints for every object. So we're not gonna talk about the the blueprint, which is the class here. Okay, in the blueprint actually we wouldn't even need to create a separate function every time because the function would be easily able to get the data from the from the object. Actually in the blueprint we can define the functions, we can define the variables, everything inside the class. So let's just do this for now. So um what I'm doing, um I can delete that but I'm not deleting them right now, why I'm not deleting them because you know, I want you to see what I'm doing and then you can compare what I'm exactly doing. Okay. So I'm creating a class now or um let's just delete it because Yeah, no problem. I deleted everything. Okay, so now I'm going to create a class class just like that. Okay, okay, I do not need the class in that. Great. Okay, this is how we create the class and what's the class it's a blueprint of of an object. So, you know, we talked about the interface. So you need to know about the interface already if you're talking about the classes because uh the interface is in the basic the basic series of the typescript. So you must know that before coming here. So if you didn't learn about the interfaces yet, so you should go back to the, you know, and learn that and then come back here. So anyway, uh the the the interface is also a way to create the blueprint, but there's a little difference because because the class is not only the blueprint, but it also helps the object. You know, initiate. It also has the implied implementations for the object, not only the defining not only the type definition, so In the class you just don't define the types. You actually, you know, make the object work using the class. In simple words, you see, it's the blueprint, for example, for example, let's just leave the class keyword for now, for example, um there are 50 human or 50 students in a class. Let's just say we have a class. A complete class. Okay. And the class has 50, I mean the school class, their high school class and each class has the 50 students. Okay. But every student should have, you know, a certain pattern. For example, every student has a certain pattern. For example, you know, every student should have a first name, should have the last name should have a rule number. These are the common things, but also every student should be, you know, qualified in mathematics or you know, something like that. Every student should be qualified. You know, let's just say a class. Okay, so we are defining the class rules in a in a general high school class. So I'm just making the high school class. Okay. And here, I'm defining the rules inside this. First of all, everybody should have the name and the name has to be strong because it's the, you know, the typescript that we have to type the no, the, the the type. Anyway, it is not necessary. I mean, if you just don't want to mention the type here, you can you can just simply ignore that. This this also works, but when we are in typescript of why not use the way types of works the age Yeah, this has to be the number, but also, you know, the qualified or not qualified or you know, finished, let's say finished uh met or let's say, you know, I'm trying to make this more real world, you know, finished middle school. Okay, so this is a question when coming to high school and this has to be, you know, uh the yes or no, if no, then, you know, so this is a question because you're talking about the high school class. So, you know, if we're talking about some class or some, you know, some group which is probably doesn't belong to school, so we can ignore that. Okay, um, middle school remarks remarks, I think this sounds more good because here finished school, maybe the other one can say no, we didn't finish the middle school, but, you know, middle school remarks, this sounds more, you know, real world because, you know, uh in when you want to come to the high school, you have to have some remarks from you got some remarks from your middle school or you can say middle school results results, it can be, you know, uh the the, you know, uh or middle school passing marks or anything which defines that, the student is actually in the high school class or eligible for the high school class. Okay, So then there are a few more things we can add if you want to um evening shift, evening shift here, I'm putting the bully in. Okay? And then the morning shift. Okay, So one has to be the true one has to be default. So I just created, you know, a kind of blueprint for anybody who wants to, you know, who wants to join the high school class. So this is the law. So now, instead of creating separate variables, these are the properties I'm gonna use from this class. So I'm gonna create an object now, but now I'm just not going to create a simple object, like O B J one equal to, I'm not going to go with this way, the general way, because this is not exactly the object oriented programming. Yeah, sure, it is an object, but not the object oriented programming. So now I'm going to use the class um and how I'm going to use the class actually. So first of all, I'm going to create the name of the object, so I'm writing C O N S T cons. Okay. And the second thing is the name of the object, it can be anything, for example, the name of the object is uh rule number, you know, I'm writing here are one are one means the rule number one or you can right? Rule number one. So we're talking about the person who has the rule number one. And what I'm doing with the rule number one, exactly is uh, um, adding equal to new high school class. Okay. So actually I have attached the class. There is one more rule when you're creating a class, the first letter should be capital and the same goes for the interface too. So you know, this is not exactly the rule, but that is the preferred method. So it defines, sorry, not hi, but hi and sorry, edge and the edge awesome. Now the rule number one has all the properties, the high school class, health. Now you need to fill the data, you need to go down and you need to call the rule number one dot. Now the name, you know, when you just see that, you know, intelligence actually defines that. You need to, you can choose anything and you, you need to put any of them. So you're going with the name now equal sign. And I'm writing here for example, the name is uh, john mark. Okay. And then the rule number one. Now I'm talking about another property. The rule number one should have, which is the evening shift or morning shift. So let's say morning shift. He is um, you know, you know, it's about, you know, I can say no yes because it is the hover the mouse, the types string is not sustainable to tie boolean. So this has to be the true or the fall. So if it's a morning shift I need to write the true morning shift. Now rule number one dot evening shift equals to false. So if that is true, that has to be false. Okay, so you can see that this data, this data is coming from, you know, this is very much connected. So I just need to call the rule number one and I am saving every data of you know name the morning shift and everything into the rule number one. So this is how beautifully you can use the class and throughout the class you can, you know create uh uh you can go with the object oriented programming instead of just simply creating the object. Anyway. Now middle school result, what was the middle school result? It can be, you know um 50% 50 per 50% results. Okay. Roll, What left? Rule # one got um age, Okay, sorry, age equals two. Now the age has to be the number I'm writing here. Um 24. That is awesome. So the name, the morning shift, evening shift, the middle school result, middle school results are should be capital here should be able to. So now we actually, you know have used a class to define this function. Sorry, this object, the object name is rule number one which has a new, new means. Actually we are assigning something new to this method to this object. So we're assigning this blueprint to this uh to this variable and this is how this variable became an object. An empty object. And then we started filling the data. So now if you call the console dot log, um and you just simply call the rule number one, you're gonna have the data, all the data to the console dialog, you know, all this data into the variable into this object. Because this object now consists of this data and this data is following this blueprint. So I think we just clearly define the everything I mean we need to know. So now I'm going to the terminal and I'm creating a few things, for example, TSC index. And I'm gonna press the sorry, not the index but the script. Because I'm gonna run, I'm just gonna, you know, convert this one into the Js, I'm pressing the enter key and uh okay, uh it just compiled the results. I'm going to the script O J s and now you can see that what happened here, ultimately it converted uh you know, the gsc converted it into the script dot Js file in the Js. This is the es five by default, you know, when you just don't conflict the TSC now about the configuration of TSC. So you again need to go to the to the, you know, the different the different castes were talking about the basic things of the typescript typescript basics. So you need to check that into in my profile, in the code cast, you're gonna get that. So we discussed about the configuration of the of the typescript. So then you can choose the ES six or seven version of the conversion of compilation for now. It compiled into the ES five and in es five, the classes doesn't just exist. So this is why it converted into the functional way. So, you know, it just created a function here. An object here. Originally an object and No, this is a function, sorry, a function here. And inside the function there is another function which is high school class which is returning the high school class and then, you know, this is the we're assigning the function here and kind of programming language. But this is a sorry, the orient object oriented programming. But this is the very old way to do that. It's still this is objectification, but this is not the way we are going because we're going with the classes way. So let's just, I mean, you know, let's just initiate the T S C I N I T. And it will create a conflict file here. Oh, you just got the problem. Mm hmm, mm hmm. TSC cannot resolve the past. Uh we'll see this in the next cast. No problem. We'll see this in the next class. The very next cast we're going to create the, you know, because this this is already going too big. So we're gonna talk about that in the next video for sure. Until then stay tuned.
152 Views 0 Likes 0 Comments

Let's go over the basics of classes in TypeScript OOP.

Leave a comment (supports markdown format)