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
An object is kind of like an object on real life.
You have something called a dresser. They all have basicallt the same shape, and they have the same available operations like “open drawer” and “close drawer”. They also have some stuff that varies between dressers. The outer dimensions, the number and size of drawers, the type of drawer pull.
So in OOP you would make an object called a dresser and each time you needed to work with a dresser in a house you would create a specific instance of “dresser” by defining thr variables for that instance and that instance would have all the operations like “open/close” available to it.
Then you start creating all the other objects you might need to furnish your place. Bed with size, sheet type, #of pillows. Methods like “lie down, sleep, make the bed” and create as many instances of bed as you need that vary one those.
Keep building till you’ve got your OOP software home with all the functions andnobject types you need.
Latest Answers