Object Oriented Programming Explained Simply

Having a hard time understanding the concepts behind Object Oriented Programming? You are not the only one. Reading documentation feels like you are learning a foreign language. Programmers love using big words to confuse people. Then we use even bigger words to explain the big words; because screw it, you can’t tell geeks what to do aaaaaannnnd job security. A whole bunch of nerds coming up with nerdier definitions. Might as well just learn Klingon… ugh nerds. We are the worst.

Researching Object-Oriented Programming you probably have come across dry definitions for the words objects, properties, and methods/functions. I am guessing you are still confused and that is why you are here. My goal is to explain these concepts, visually, in a simple method. So simple, I even included a video, you are welcome.

Some nerds are going to complain, bla bla bla other ways. The point of this article isn’t to be language specific, OR even remotely complicated. I am limiting the coding examples, using simplified language, and simplified syntax. The point is to define objects, properties, and methods in a visual way. Simple language, simple definitions, and simpler examples.

Now let’s start.

In Object Oriented Programming, objects are like cars.

Yup, cars. Look at the image below. The image to the left and right are both cars yes? Can we agree on that fact? Yes? YAY.

How do we know they are both cars? Well for one, they both have four wheels. They have windows. They have doors. They both look like they drive. They both look like cars and do tasks that a car would do. They are both cars. What is their object? A car. They might look different, but they are still both cars.

Again, objects are like cars.

Think of an object in programming like an object in “real life”. Something you can touch, like a car.

Look at the cars. Get out a piece of paper or open a document. Jot down the differences between the two cars? What makes each car unique. Is it the brand, the color, the type, the make?

Which properties did you use to describe the cars? (keyword properties).

Properties describe the car.

What are the properties of the car on the left? Is it blueish? Is it a Fiat? Yup, those are properties of the car. You can see I listed a few of the properties in a boiled down javascript syntax.

Now time to break down the example:

car.make = "Fiat";

Another way to look at it is: Object.property = “descriptor”;

Or in English, The car make is a Fiat.

What are the properties of the car on the right? It is white. It is a sports car. Yup, those are a few of its properties.

Describing this object in javascript.

car.color = "white";

In plain English, the car color is white.

One more exercise, to seal the deal on properties. Look at the javascript code below. Open a new browser tab, and search for an image of this car. What would you type in Google?

var car = {
 make: "Ford",
 model: "Explorer",
 year: 2010,
 color: "red",
}

Would you Google: “2010 red Ford explorer”? Perhaps you find images like this?

Try to search for an image of this car.

var car = {
 type: "sports",
 year: 2016,
 color: "yellow",
}

What would you type in Google? Yellow sports? Probably not, you would get some strange results like this:

You would put in “2016 yellow sports car”.

The first example’s properties provide a more refined result. You need to remember this when describing your objects. I only describe the car as well as I specified its properties.

Now that we have described the cars. What do both of these cars do? Stepping into a car you probably first start it.  Starting is one thing the car does, at least we hope it starts. Pause and think about “what do cars do?”

A car starts. It can turn right, turn left, go backward, forward, etc… these are tasks a car does.

Methods are what the car does.

For example, written in javascript:

car.drive();
car.brake();
car.stop();

Breaking this down.

Object.method();
WhatItIs.WhatItDoes();

Think of methods as commands. You are commanding the object to do something. CAR I COMMAND YOU TO DRIVE!

car.drive();

In English, DRIVE THE CAR!

If you know javascript, you will see that the .drive(); looks a lot like the syntax you use to fire a function. For example:

// Defining the function
function helloWorld() {
 console.log(“hello world”);
}

// Firing the function
helloWorld();

Look at line 7. Notice the syntax. helloWorld(); looks a lot like car.drive(); doesn’t it? The only item missing is the car. You can think of “methods” as functions for that object. Or what that object does. What do I mean by that?

food.drive(); doesn’t make sense. What food does is different than a car.

That is it:
Objects are cars.
Properties describe the cars.
Methods are what the cars do.

I hope you found this article about object-oriented programing helpful, now keep coding.