What is Object Oriented Programming?

861 viewsOtherTechnology

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

25 Answers

Anonymous 0 Comments

At its simplest, I like the old “recipe” metaphor. An object is a cake. A class is a recipe for a cake. If you need a cake, you use the class to instantiate an object. If you need 2 cakes, you use the class again. The two cakes are separate and unrelated to each other, but you know exactly what’s in them and how they taste.

That is, you know the methods they have, etc. You can interact with any number of cakes, because you know what “cake” is capable of, by examining the class (recipe).

There are many other aspects of OO programming, some of which are controversial (ask an old-school c++ coder if you can call something object-oriented without “inheritance”) but that’s the key: you define a class, and then you know how to work with any object made from that class. Very useful as your program grows in scope and scale.

You are viewing 1 out of 25 answers, click here to view all answers.