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
Think about it literally: an object in the world. The kitchen sink, for example.
Your sink probably isn’t an artisanally hand-crafted original, it is based on a plan (i.e. the definition of a ‘class’ or ‘type’ of object). The plan lists all the properties of the sink: it’s height, width and depth; its material (chrome or enamel).
The plan also lists the functions of the sink. The toggle stopper function allows water to be held in the sink, or sent down the drain. The faucet function takes input from the user to provide either cold or hot water. And there are handles to act as an interface to provide precise input within required constraints.
Your sink is an instance of that plan. It has all the properties and functions of the plan, as does any other object of this specific type. But it can also have properties related to its present state. Full or empty, dirty or clean, functional or broken, etc. In this way, your instance of the sink may differ from another instance of the same sink plan, or from the plan itself.
Latest Answers