Placeholder Image

Subtitles section Play video

  • Are you confused by the terminology of object oriented programming such as constructor class, New keyword, Instance station and so on?

  • Well, in today's video, I'm going to be going over all of the basics of object oriented programming, so you no longer get confused by these words.

  • Let's get started now easily.

  • The most confusing part about object oriented programming is the differences between a class and an object.

  • And simply put, a class is going to be a blueprint.

  • Essentially, it defines all the methods that defines all of the different properties that are objects can have, but it doesn't actually give it any data or information.

  • It's just a blueprint, a holder for what our object is going to look like.

  • An object, on the other hand, is an instance.

  • She aided version of a class.

  • Essentially, it's a specific version of a class that has all the extra information filled in, such as the different values for the properties and what all the methods were going to return.

  • So this is very similar to how a house and a blueprint work.

  • A blueprint is going to be the same as a class.

  • The blueprint defines what we want our house to look like in general.

  • It's going to be where the walls go, where the different rooms are.

  • But the blueprint doesn't tell us what color the house is going to be or what furniture is gonna be in that house.

  • The actual object itself or the house in this instance is going to tell us what the color is and what the different furniture is going to be inside of it.

  • But not the blueprint, which in our case, is the class and then moving on.

  • From there, we have the new key word.

  • The new key word is how we actually take a class and turn it into an object.

  • And to do that, we use the constructor inside of the class to make all of these different points concrete.

  • Let's look in an example in actual code using JavaScript to illustrate this, we just have a blank Java script file which we're going to first create a class in, which is going to be our blueprint.

  • So we're gonna clear your class.

  • We're gonna call it house because this class is going to be used to create house objects and inside of here What we need is a constructive so we could just type the keyword constructor and the constructor is going to take all the parameters we want to put into our house when we create a new instance or a new object of that house.

  • So, for example, we want to know the color of our house because every house we create is going to have a different color.

  • And then inside of here, we can just set that color.

  • So we can say this dot Koller is equal to color and this is just going to save our color onto our house object itself that we're creating now all we can do is come down here.

  • We can create a very book where is gonna call it house object?

  • Because this is going to be the actual in Stan.

  • She hated object of our house.

  • We just want to set that equal to a new house.

  • And the reason we use this new keyword is because by putting the new key word before the name of the class But in our case house, it's going to call the constructor with everything we pass into the brackets here, these curly are thes parentheses here.

  • So if we pass in the color, for example, read Now, this is going to pass this red variable in here for color, and it's going to set it on.

  • Our house is going to create us a new version of this house class, which is going to be an object, and it's gonna save it in this house.

  • Object variable.

  • And, for example, if we wanted to have a function on our house that got us all the furniture in our house, we could just say, Get furniture and we just say it takes nothing and in here is just going to return us our furniture, which in our case is just a single sofa, and this function is going to be shared between all the different instances where all the different objects off our house class.

  • So let's create another house object here.

  • We'll call it House object to, and we're going to make this one blue.

  • And now what we want to do is we actually want to log out some information about our houses so we can come out here and we could just consul dot log our first house object, and we just want to get the color of it.

  • And we're also going to call that function, which is get furniture and see what this is returning.

  • We're gonna do the exact same thing, but for a second house down here.

  • So we're gonna say house object to and to save that and now it's actually see what that returns.

  • If we see over here, we have read being returned as the color of our first house.

  • And so for being returned for our furniture and you share a blue house has blue been returned, his color and again sofas being returned for the furniture.

  • Because this function is on the definition of the class, which means that shared between all the different objects house, object, one and house object to.

  • But this color is being variable.

  • It got passed into the constructor.

  • So this is being changed based on what we passed in here for our new house.

  • In our case, the 1st 1 is red and the 2nd 1 is blue.

  • If you want to see more videos of me simplifying programming terminology, let me know down in the comments and I can turn this into a full series also let me know what other terms you want me to cover in the future.

  • Thank you very much for watching this video and have a good day.

Are you confused by the terminology of object oriented programming such as constructor class, New keyword, Instance station and so on?

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it

A2 object blueprint furniture class returned defines

What are Classes, Objects, and Constructors?

  • 0 0
    林宜悉 posted on 2020/03/28
Video vocabulary