OOP with TypeScript: Understanding Objects

TypeScript
Transcript

English (Auto-generated)

So for example, you know, you're talking about somebody else. So you're talking about me or anything else. So what you do you for example create my details. Let's say you're collecting my information. So you say things like you know name. Um let name. Let's just save it. So I'm saving it as uh um script dot T. S. Okay. This is typescript thing. Okay. Let name equal do string, you know, equal school. Um Okay. And let let's say father name string equals two Tamal. What is the problem you have buddy? Um Okay, mm hmm. My name actually the name is a reserved keyword. You need to know that javascript has a javascript or the typescript post has a lot of reserved keywords and we cannot use them to create a variable. Anyway, these are two things and then let um age. Okay. And it should be the number equals to um writing here. 28. Okay. That's awesome. So these, we just put three things right now. We can make a lot of things and uh you know, so let me delete that. And uh here I'm creating a function function and the name of the function. I'm writing it as uh full name. Okay. And uh and here inside the inside this function I'm writing um let's say return okay. And also it has to be, I mean we will think of it later and if I return my name plus. Okay and sorry and father name. That's awesome. Now simply save it and what and what next um you simply need to call this in the control log the full name. Okay, so once you call this in the, in the control log you're going to get the result as the, you know name and the name of the father name. So this works and this works well. So the problem is, I mean when you need, you know, this is one person, this is Shazia and the data of the is mixed and uh this data is, you know, not exactly here. One more thing actually, you know, you need to get these values in the, you know, in the parameters for example my name. Um actually yeah, we can go with the parameters but in in that case we have to get the data. Um we have to get, we have to put the name here. Then it will be totally functional programming. But anyway, so the name, the father name and the age. So this is the functional programming. But the problem is for example, you have one more person, let's say you have Mark, john or john Mark or whatever. And now you want to put the data of jOHN so you have to create this function again and you have to change the values of the variables and then, you know, maybe we need to know, we need to make some more functions about me for example, maybe, you know, I'm gonna add some of my features, my personality traits in the variables and we want them to be, you know, to be uh we need to connect several functions together to get the result and and that code is actually called this called the spaghetti code. And in that way when you change anything, you know above everything from the whole, the program won't work. So you have to be very careful. So the solution is quite simple. Let's say you're just gonna make a function uh an object, let's say const Oh, BJ one for now. It is oh BJ one but equal to and this is the simple way you're going to write my name and the type is sorry, string and uh wait my name. Yeah. Um Okay, this is an object. So you just cannot just write a string method that way. If you want to create a string method, you have to use 22 ways. Okay. One way would be the, you know, the uh the interface you can go with interface. The second method is the classes. There is a little difference between the the classes and there is a very big difference between the classes and inheritance. We're gonna talk about the classes in the next cast. So you are going to know about them later. So we already had a discussion about the inherent in the about the interfaces in the in a different series of the typescript. You can just go there and the basic series of the typescript where we had a talk of the interfaces anyway, so this is and the next one is the name. Come on. Okay. And then the age And the ages, you know, 28. Okay. So this has to be this way And now that's fine. Now this is the simple function without any type, you know, types. So if you want to have some types, you have to go with the classes, we're gonna talk about classes in the next cast anyway. So now, you know, now whenever you are going to create this kind of function, you just simply need to call if I just copy that and paste it here. So um Full name one, let's say. For now it is full name one. And here it can be, you know, oh, BJ one dot my name. Now when you write o b j 00.1 dot my name, you're talking about this object. So when you write oh, BJ one dot father name. So you're talking about this object again. Now, you know, here the my name and my father, the father, Neymar not connected. They're different. Which is, you know, very awkward when you're talking about the same person, everything should be connected. Including this function. So an object can also consist of a function when you're you're going to be proper object oriented programming for now, I'm just creating a simple function in the next video. Absolutely. I'm going to create the uh the functions and methods actually the functions are called methods in the GOP. Anyway, so I think for now we just got it and we just understood the way it is. These are the, you know, this does the same thing as this does, but here everything is connected. But it's still the function is not connected but that is an object. And the concept of object is to collect everything of an object in one place, even, you know, the properties of the the the object, the methods of the object. The method you can say is an action, every action of the object. So here everything is open and it can be anywhere and you just need to collect them in a function. And the function is actually the method or the action. So whenever you want to make, make some act so you use the objects properties and make them back to using the function. But here in the in the object, the everything of the object including their methods, their properties, everything should be in one place. So this is the basic concept of the object. And in the next video we're gonna go with the we're gonna go into a little depth of the objects. So until then stay tuned
105 Views 0 Likes 0 Comments

In this video of the OOP TypeScript Series, we are going over Objects.

Comment
Leave a comment (supports markdown format)