I can’t really wrap my head around OOP. Like I understand an array and a function and a variable, but I don’t understand what an object is. Why can’t we just use functions and variables everytime we need information or code to run? I code in Python and JS mainly, so objects are truly the most important thing, but I don’t really get it. Also, isn’t every program object orientated? Even C, does it not fit the definitions? If so, how is it any different from C++?
In: Technology
Objects are collections of stuff treated as one thing.
Let’s say you are an object. Your object type is “human”.
You have an array of properties that makes up you as an object. For example, your “gender” property, your “age” property, your “name” property, if you are alive or dead, etc etc.
This let’s me do a lot of different things with your object while still treating you as one thing instead of as a collection of traits.
For example, I could get a program to output me a list of all “human” objects whose “gender” is male, who’s “age” is between 18 and 35, and who is alive. If I wanted information on you specifically, I could find your object and look at all of your properties.
Basically, objects let you treat collections of related information as part of one collective thing.
Latest Answers