Explain It To Me Like I'm Five: Object Oriented Programming
11 January 2013
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.
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.
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".
This is the general idea behind object-oriented programming.
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:
(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
Favourite food = pizza
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?