Explaining OOP: Using a Layman’s Example

Peculiar Ediomo-Abasi
Today’s Code Newbie
3 min readSep 17, 2023

Object-oriented programming (OOP) is a term I have loosely heard, but I’m learning about it now. I’m taking some baby steps towards understanding some engineering concepts. And I will write as I learn.

In this article, we will explore what OOP is about as though I am explaining it to my grandpa. Let’s ride along!

What does Object-Oriented Programming mean?

OOP is a style of telling a computer what tasks to perform to solve a problem. This style requires some components. Let’s use a kitchen illustration to explain further.

OOP:     Style of baking cake
Class: Baking pan (Template)
Object: Different types of cakes made from the pan

You can use the same class 'baking pan' to instantiate 'bake' many
cakes 'objects'.

What is a Class?

A class is a blueprint or template from which objects are created.

A class 'baking pan' can have properties like:

- Shape
- Height
etc.

These properties have their values. For example.

- Shape: Square, circle, rectangle, etc.
- Height: 2 inches, 3 inches, 4 inches, etc.

When a cake 'object' is baked 'created', it inherits the properties of the
baking pan 'class'.

What is an Object?

An object is an instance of a class.

You can bake mutiple cakes using a baking pan.

1. Each cake will have all the properties of its baking pan.
2. Each cake can look different, based on the property value of the baking
pan used.

For an example,

Cake A: Rectangle, 3 inches.
Cake B: Square, 6 inches.

Cake A and Cake B are instances of the class 'baking pan'. Objects!
Also, these cakes can have different attributes.

What is an Attribute?

An Attribute stores information or values that describe the object’s characteristics or properties.

Cake A and Cake B can have different flavours, such as chocolate, 
vanilla, or strawberry, etc.

Other attributes 'adjectives' that can describe the characterisics of the
cakes are:

- Type (such as carrot cake, velvelt cake, chocolate cake, etc.)
- Ingredients.
- Baking temperature.

What is a Method?

A method is a procedure defined within a class that specifies the behavior or actions that objects created from that class can perform.

Within the class 'baking pan' the following methods 'actions' can be defined:

- Bake Method: This would represent the action of baking the cake.
- Weight Method: This could determine the weight of the cake.

Actions: A baking pan can allow you bake a cake. And, it holds the
weight of all the ingredients you put in it.

In Summary,

We’ve explored the concept of classes, objects, methods, and attributes, in simple terms. Classes served as baking pans, objects were the various cakes created from those pans, and methods were the procedures guiding the baking process.

As we wrap up this article, remember that OOP, like baking, entails using templates to create unique instances and defining how they behave — it’s a powerful tool for solving complex problems in the world of software development.

So, let’s keep taking those baby steps towards understanding engineering concepts, one analogy at a time.

--

--