Object Oriented Programming(OOP)

rotimi abayomi
3 min readApr 19, 2021

OOP is a programming model that simplifies complex programs into reusable programs.
This model privileges how a program is built rather than the functions it can achieve.

Using a car as an example, a car is a very complex object made up of different pieces and functions. Rather than focusing on the function of the car which is driving the car, we shift our focus to how the various parts of the car can work together.
The simplification of the car can be classified to its different parts which include:
* The Engine
* The Steering
* The Wheels
The Engine starts the car, the Steering moves the wheels, the Engine provides a force to push the car.
With each simplification we see how all these parts interact with each other, and it’s easier to make another car with same or different structure.

Classes

The class is a blueprint.
In normal terms, a blueprint is a piece of paper that acts as a guide for making something.
In programming, it is a reusable pieces of code(set of instructions) used to make different parts of a program.

Every car has a steering, an engine and wheels, a blueprint can be made for the creation of these parts.
Using the wheels, we know the wheels:
* Are spherical
* Uses friction
* Uses suspensions
We can define all these in a class to make creating a car wheel easier and reusable.

Objects

What is created from a class is called an Object. The same way a Car is created from a blueprint(architecture), the Object is created from a class(which we defined earlier as a blueprint).

Without the Object’s created from the class, there will be nothing to interact with(we will see but can’t use).
We can draw a Car on paper but can’t drive it, we can build a Car and drive it (Clear contrast between Class and Object).

Like the car example, the wheels have to be created for it to be used, the car needs the wheels to move.

Concepts of OOP

Inheritance

This is used to extend information. Information can be reused without rewriting what you have done previously.

A car may have different types: Car, Truck, Motorcycle and so more. All these are cars and behave like a car, they obtain the features of a Car and use it for their own purposes. All these behave like a car.

A normal example in this case is between parent and children, the child is said to have the personality of their parents, the child reflects the parents. The parent of a child can be identified from the behavior of the child.

Encapsulation

Encapsulation hides information the user doesn’t need to see or change. Direct access to these information isn’t given to the user.
If indirect access is given to the user, the original value of that information doesn’t change, it’s new value is only temporary to when it is used.
An example in the case of cars will be Engine power, we know some cars move faster than others but we can’t directly change the engine power of the car, that engine power is hidden to the capacity of the engine.

Abstraction

Abstraction hides details that the user doesn’t need to see.
When we drive a car; we don’t care how it moves, we only hit the pedal and get to our destination.
This case is highlighted more in manual cars where changing gears is more seen, we don’t know what changing gears does to the engine, we do know it affects our speed.

The user doesn’t need the details but the final outcome of the process.

Polymorphism

Polymorphism means different ways in which they work or operate but generally the same thing.
Cars have multiple ways of moving, we have two wheels, we have three wheels, and fours wheels and all the different cars although drive differently but still get to the destination.

Taking an another example, all animals walk differently but they all can get to the same destination, some animals walk with two(2) legs, some with(4), some even fly. But all these animals move, different ways in which they move but its still movement.

Benefits of OOP

* It is reusable
* It has a simple structure
* Protects information

Summary

OOP is a model that create’s blueprints and make objects from the blueprint. It makes program’s easier to maintain for the programmer and use for the user.
This is a simple overview to OOP.

--

--