Blog


Explain It To Me Like I'm Five: Object Oriented Programming

11 January 2013
MS Paint drawn pet shop


Imagine you walk in to a pet store. A pet store has lots of different animals. You walk in the section where all the dogs are. There you find a very wide variety of dogs to choose from.

The dogs in the pet shop come in different sizes, different colours and different breeds. We can therefore describe each dog in the pet shop by its size, colour and breed.

MS Paint drawn dogs


For example, one particular dog can be a "large, brown bulldog". Another dog can be a "small, white chihuahua".

We can say that dogs are "objects". So are other things like their cages, their food or the ball they're playing with. But imagine if everything around you was to be called an object. Everything from flowers, to cars, even people, your friends, or dates or years.

Everything is an Object


So imagine that we want to describe your friends. We can say their name, their age and their favourite food. For example, "Bob is 6 years old and likes pizza", or "John is 5 years old and likes hamburgers".

Bob and John are objects too!


This is the general idea behind object-oriented programming.

Analogy



Dogs can be described by their size, colour or breed. We can therefore create a "blueprint" for describing dogs based on these characteristics. In programming this is what we call a "Class".

Here is a simple code example of the Dog class:


class Dog
{
String size;
String colour;
String breed;
}


(see footnote 1)

Now if we want to describe a specific dog, we can use these three characteristics:

Size = large
Colour = white
breed = chihuahua

The specific dog that we've given characteristics to, is what we call an "Object".

As we said before, you can describe your friends by their friends, their age and their favourite food. Therefore, the "Class" called "Friend" would contain these three characteristics.

Each of your friends (or your friend "Objects", since we're calling everything objects) must have these characteristics. For example:

Name = Bob
Age= 6
Favourite food = pizza

Footnotes



1. Yes, I know this is not the appropriate way to structure a class, but I'm trying to make it in a way a five-year-old can understand it.

You might also like:

22 April 2013 - Gradester for Android updated to 1.5
14 April 2013 - Updates on version 1.4 of the Gradester Android app
10 April 2013 - Version 2.0 of LSX is here. What's new?
25 March 2013 - Dear Larry... We need to talk...
02 March 2013 - Who needs it anyway?

Comments

About Me

Savvas Stephanides
Hey there. I'm Savvas, but you can call me Sav. I am a Computer Science graduate. I like programming, designing clean and useful user interfaces and learning about Internet memes. I mostly code in Java, for desktop and Android applications, and PHP for web applications. Want to talk to me about anything? Drop me a message through the Contact form. Here's where you can find me:

2012 Savvas Stephanides. Contact me. Like me on Facebook, follow me on Twitter or see my professional profile over at LinkedIn.