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

OOP is one of the most misunderstood topics in programming, but let me try to take a whack at it.

First off: One of the hardest things about programming is managing state — Your program has a bunch of data in it, who’s responsible for effecting changes to each piece of data such that it’s guaranteed to remain correct at all times?

There’s a number of approaches that help with this problem, and OOP is one of them. The core concept of OOP is _Message Passing_ — instead of all parts of a program touching any and all data directly, you have different components of the program that each own some of the data, and components talk to each by passing messages around, asking other components to manipulate data on their behalf. Because each component wholly owns its data, you have only one place in your program (the definition for that component) that has to make sure that it responds to any message it receives by leaving the data in a correct, consistent state.

I specifically avoided the usual OOP vocabulary in that description — in OOP, what I called “components” are usually called Objects, and most languages implement message passing in terms of methods, which are basically just functions that take a special parameter that points at the data owned by the object (usually named `this` or `self`). There’s more than one way to do this, but the most common approach to implementing objects in a language is through classes, which are effectively a template for what data and methods an object has available to it.

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