OOP with TypeScript: Encapsulation Part 4

TypeScript
Transcript

English (Auto-generated)

I mean we are going to apply it in encapsulation in the real world as a real world example. So what I'm gonna do here is actually okay, this, I'm deleting this because this is what I'm going to talk about now anyway, for example, you know, um when we wrote, when we created the console log here, we can see that this is the previous lecture, we created that and we, we put the, you know, we took the full name. Let's just test it out for once. Okay. And no duh script dot Js, let's throw something is um okay, I wrote scripts dot Js, not a script dot Js. Now it should be, it should be working okay. First of all, we do not need this object, the person, we do not need that. So I'm just simply going to, this is the name of the object is a person here, but whatever, but we just simply do not need that because it's unnecessary. Okay. And eventually it's not, you know, reflecting the object itself, but it's reflecting reflecting the class. It's reflecting the class and it's uh sharing the data uh, of the object with the class. Anyway, we do not need that anymore. I just simply, I'm deleting that. That's better. Okay, John Mark is a potential person, it's ages 50 and has black hair. So maybe you want to talk about his age because it's a meal that John Mark is a meal. So the meal, the meal has should have his age and his his height, not the height. So okay, the height of john mark, that's okay, But this should be his or her. Maybe it can be the lady, it can be the mill the the guy. Okay the boy. So for now it is uh it is it's it has to be his or her. So what we're gonna do we're gonna create the gender P. One and that. Okay sorry we need to create the function here right here. Okay 1st I'm Gonna create the private private. Okay And I'm gonna write the general, it has to be the spring and that's understandable. So how we're gonna get the data of the general set general and uh general string. Okay we're gonna go here and we're gonna go inside and we're gonna talk like this dot Jenner when we're talking about this dot general we're talking about that one uh the property of the person the person class and equals two general. Okay so this dinner is actually the parameter. We're gonna get the value of this this general when we're calling the property of the object. So I mean things are very much explaining catering a similar method. We're going to apply. I'm going down and you know I'm gonna call the P. One brought set general. And here we're gonna apply it as meal for now. Okay that's good. Now I am going to do one more thing. If the Jenner is meal then what should happen. What should exactly happen is pronoun spring. I'm not making it private. I'm just trying to show you that it is not important to put the the private but it is important by the way because you know it will work. But if you don't make it private it can be changed. The value of the pronoun can be changed by simply calling p. One dot pronoun. Okay. So you want to make it private? It is not you know it will work. But it is necessary when you don't want it to be changed but maybe you want it to be changed in some aspect of programming maybe you want. So you just can you just don't need to put the private label label. Anyway. Uh what I'm gonna do here, I'm gonna simply go down and uh what I'm exactly gonna do is mm hmm. If janitor equals two meal then the pronoun should be okay. I need to call it with this. But pronoun because you know we're talking about something which is not a part of this function but the part of the class. So the pronoun should be dinner, whatever. Sorry. The pronoun should be his. For now you can put him you can put her, you can put whatever you want. Just showing you then else if If the general equals two female. Okay. And then this dot pronoun equals to hurt. Okay, that is understandable. The pronoun. We were using this thing. The pronoun. Okay. So what else? Uh what else we need to do. We just need to go down what is happening here. First of all, let's talk. We created a private as general. A private property as general. Okay. And we're getting the data actually. We do not even need to create this private property as general. Let's just make it silent for now. And uh let's just believe this one because we do not need to do in case you want to save the data, maybe you want to store the general in the object then you need that. Otherwise it is not important for what you're doing. So we simply created a set general function or set pronoun. You can also call it set pronoun uh set religious qualities. That general for now. So here we are getting it. Set general as mill. So here the general strength, if general is equal to mill then the pronoun should be his and if the general is female then this dot pronounce should be heard. That is self explanatory. Now what we need to do, we need to you know because it's private here. It is private. If I don't make it private and I just in college which is not very cool. So I can update it this. Sorry p one dot We cannot call this year because we are out of the the class. So talking about this means something which is here nearby the you know, in the same scope. Anyway. Sorry pronoun, this would work perfectly. I'm going there and I'm making PSC And then I'm doing notes, pace, script.js and then you're going to see John Mark is a potential person. His age is 40. So let's say you make it female in case and you just do the same here, TSC and then no script dot Js and then you're gonna get her age. Now if you make it private, private. So absolutely, this won't work. Even we got we got the error here. This wouldn't work because it's a private property. So now you need to use the, you know, get general too. So they get general. Okay. General, mm hmm. And you're gonna call return of this function should be this dot pro now. Okay. We're not using the general anymore. In case you want to see if you want to store the data of male and female. The general, I mean male or female with the object, which is good, which is a good thing. I mean, you know, so you can save that in that scenario, you can do that. And in that scenario, if the general is male and then, oh sorry, you just, it's not general equals food. General. Okay. If it's meal, then ultimately it's gonna have the, you know, this private dinner gonna get gonna get updated itself as general as male. Otherwise it will be female. And here the pronoun should be, you know, variable. It can be his and her according to this if entails. So I think things are pretty much explanatory now because we made the get general, so we need to go there and we need to call the get general and then we are going to get the results clear PSC. And then I'm gonna see no the script dot Js and then her age using the get dinner because it's a private, it's a private, you know, uh probably here you just simply cannot call it. So I think it's pretty much explanatory making it meal. I'm calling the PSC again and I'm gonna call the node script dot Js and then his age. So I think we just did it and we're good to go for the next video and encapsulation concept is actually clear with a real life example. So till the next video stay tuned.
81 Views 0 Likes 0 Comments

Let's talk about encapsulation.

Comment
Leave a comment (supports markdown format)