What is Object Oriented Programming?

865 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

Here’s a 3rd year CS students explanation, one of the main reasons to use object oriented programming is to define objects with states which can be a mix of mutable and non mutable. For example say you’re writing a simple program that defines a car in GTA 5. There are many types of cars each could be using the same model but that doesn’t mean they’re the same object. You would probably create variables that define color, speed, amount of doors, durability, and then even more specific things like whether the tires have been popped, whether windows are broken(so you can fire out of them).

Now I’ll decide not to overwhelm you but I must mention classes to some extent because they’re also interesting. A class essentially stores a blueprint for any kind of object, for example you could create a class that is used for all vehicles in the game, and then you would have sub classes for planes, cars, boats, bikes.

Quickly you’ll realize that making objects allows for intuitive code reuse and general approach for organization. With OOP you’re basically nesting a lot of boiler plate in a generic class so you can focus on the real details instead of having to define a vehicle everytime.

Say Rockstar wants to add a flying boat, they could simply inherent attributes from the vehicle super class, flying vehicles, and boats. Tada you don’t have to define a very simple flying boat because all of the code is already there you’ve just created a brand new object using a scary word called polymorphism(no longer so scary).

It’s incredibly useful but has its drawbacks, python also uses OOP so feel free to explore the paradigm.

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