How does Object Oriented Programming work? What does it do and how is it effective?

1.12K views

How does Object Oriented Programming work? What does it do and how is it effective?

In: Technology

10 Answers

Anonymous 0 Comments

Given that I’m not sure how familiar you are with programming, I’ll base my assumptions on the fact that you’ve heard of Object Oriented Programming (OOP).

TL;DR OOP is good because it chunks related information and actions (variables and functions) together.

If you’ve done any amount of programming, you’re likely aware that sometimes, a set of variables are related. E.g. a “person” might have a name, an age, and a birth date. In functional programming, this could be a struct or just a few loose variables. The thing is, with large applications, passing all of these things around gets cumbersome.

With OOP, you could have a Person class which has all of the relevant data, and even some related functions (aka methods).

OOP also promotes reusability of code. If you have a Person class in one application, all you have to do is copy or import the class to a new project and it should work. Functional programming tends to run into the trap of code being too entangled with each other to be reused easily.

That said, OOP can be used like a functional language (just have 1 class and use only the main method + helper methods), and most functional languages can be made to look a lot like OOP (in C, a struct can have variable and function pointers, and if you split these related variables and functions into their own files, it’s not that different from OOP).

Additionally, OOP tends to make more sense to humans, because in the real world we have objects that do things, and OOP let us basically model that in code.

Does that make sense?

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