OOP with TypeScript: Polymorphism

TypeScript
Transcript

English (Auto-generated)

types um it is a part of the polymorphism. And let's just let's just discuss about it in the in the typescript object oriented programming. So for example, we're going to continue from the previous class because that was the super keyboard is is also the part of the polymorphism. So we're just gonna continue with that. So for example, here you can, you know that this is a person, the general person class and that is the the student which is the extended class of the person. So, absolutely, a student is a person. So ultimately, whatever the person has whatever the whatever the abilities or the properties uh the actions a person can do or perform absolutely can be done by the student, but the student is also uh student also has something different which is like grade, you can see that, then maybe the student can walk differently. However, student works similarly like a person, but we could have called it like, you know, the model, the models, you know, uh the actresses walks a different in a different way, like catwalk. So anyway, so we discussed this method, the super cute and everything, but there is one more interesting thing we have here, which is uh which is we're gonna discover by now, for example, we have another method here and I'm gonna apply that right now, for example, it is uh a student fest or um exams, exams. Okay, this is something only a student can do. Not every person, you know, does the exam things. So anyway, console dot log and here um sorry, we're just gonna return it return and what we're going to return exam passed, whatever. I mean you can write anything you want to and now I'm gonna go down and I'm gonna write a here cancel dot log. And uh in it s one because I'm talking about the first student and I'm, you know, you can see that the age, the exam, the full name, the grade, the general degrade the nationality and walks everything. We have the age. Um If you talk about the age we have the age of the person. If you talk about the exam, the exams are the part of the students. If you talk about the general generally is a part of the person. Again, you know, we already have a discussion on it, I'm going to talk about the exams only. So um let's call the exam and save it now if I just go there and I write TSC absolutely, I'm gonna I'm gonna get this file updated and then we need to run um claire no doubt. Mhm script dot Js And you're gonna get this person walks student walks exam passed. So the exam pasts are the part of the student class, but if I just go there and right here I actually right person. Class person, okay, what does that mean? I mean the student is already a person okay. It makes things a little tricky but just focus on it. The students are already, the person, a student is a person, But now the type of, the type of this object is a person too. It's a student which has everything the person class has. But now, now the type of this S one is also the person. So any function, any method we have in this student will not be tolerated in this object. So this is a way, I mean, maybe, you know, you want uh the S. One to be the student, but it's still you want you only want to stick the S. One with the person. So you actually assigned the type. Now, this class has the type of the person. So you, you know, you can see that the exams are not the part of the person classes or exams are, I cannot work with this student with this student object. The the exams cannot work. The great cannot work because these are coming from this student. So if I just right here? S1, you can see that now only persons, elements like age, the full name, the general, the nationality in the box can work. But for example, if I create another one, wait a minute, if I delete that, that makes it more good cons spaces too. And here, I'm not assigning anything, I'm just writing a student. Okay, now, if I go there and I right? S. You can see that age example name grade, but if I write S one and I, you know, I right now we can see the exams and the great because the exams and the great belongs to the students and this Astrakhan has a type person. So I think this this makes uh, this makes sense. So in that case you have to make it's silent this way and then it would work fine. So now you can just, we can just move on to the next topic in the next cast until then stay tuned.
206 Views 0 Likes 0 Comments

We go over the concept of polymorphism in TypeScript.

Comment
Leave a comment (supports markdown format)