OOP Concepts for beginners: Illustrated guide

Beginners usually struggle to grasps OOP concepts. I trust that with this illustrated guide, beginners will get a better understanding of the basic OOP concepts.

What is programming?

“The process or activity of writing computer programs.” Oxford dictionary.

“A computer program is a collection of instructions that can be executed by a computer to perform a specific task” Source Wikipedia.

So, programming is a process, and through it, we “tell” the computer (using instructions) what to do.

Programmers, basically learn how to give instructions to computers.

These instructions can be organised in different ways. To do that, we have different paradigms. Informally, a paradigm is just a way to do things. At your home, there are paradigms all over: the way food is cooked, the way interact with your family, etc.

In programming, there are also several paradigms. In this case, we are interested in the Object-Oriented Programming Paradigm.

To write programs, we must use a Programming Language.

Programming Language

When we communicate with another person we use a language. There are many of them: English, Spanish, French, etc.

example of conversation in english and spanish language
example of two programs using Java and Python programming language

To write computer programs we also have many languages. We call these languages Programming Languages. Some of them are Java, C++, C#, Python, etc.

In the same way, you know how to communicate in English, but maybe you don’t know how to communicate in French, you can find programmers that know how to write computer programs in Java, but they don’t know how to write computer programs in Python.

Also, in analogy with the real world, you can find a person who can communicate in several languages. In the same way, you will find programmers that can write computer programs in several languages.

It is common, that programmers know several programming languages. But all of them started learning one. The same way you have a mother Tonge, and later on, you probably learn another language at school.

Another important concept you have to master is Object-Oriented Programming.

What is Object-Oriented Programming?

Object-Oriented Programming (OOP) is a software development paradigm. It states principles, rules, design methods to solve real-life problems using an object-oriented programming language.

Object-Oriented Programming is a paradigm that guides us on how to design and implement computer programs (also called software).

To learn this paradigm, the first step is learning the concepts.

Find below the most important concepts to know before even start writing the first computer program using the Object-Oriented Paradigm (OOP).

In programming, we regularly use abstractions as a way to simplify the solutions we create using a programming language.

Abstraction

Do you know all the components that are inside a cellphone?

The answer to that question is usually no. Yet, you know how to use it.  In this case, you don’t want/need to know all the components that are inside the cellphone. That is why, for you, a phone is just a device that you can use to make phone calls, send messages, install apps and connect to the internet (and maybe an extra few things). Although there is a lot more to it, you don’t need to know everything for you to use it.

Example of abstraction from the real-world that is applicable to programming
Example of abstraction from the real-world that is applicable to programming

That is the principle we follow to create useful abstractions in programming. We model the aspects we need to solve a specific problem and we omit the rest.

Abstraction is “the purposeful suppression or hiding of some detail of a process or artefact to bring out more clearly other aspects details or structure” Timothy A. Budd.

You can find a more detailed explanation at this link.

Objects

Objects are things that you can find in the real world.

In the illustration below, you can see some objects from the real world.

Objects from the real life as way to visualize objects in programming
Objects from the real life as way to visualize objects in programming

These tools have characteristics that identify them. For instance, each of them has a name (hammer, plier, screwdriver, etc.), size, colour, etc. In OOP we call these characteristics attributes of the object.

The state of the object are the values of all these characteristics together.

We can use the tools to build or fix other things. So they have a function.

In Object-Oriented Programming, we call those functions methods or operations. They are the things you can do with the tools, how you can use them. For instance, we use a screwdriver to screw (an operation or method) or unscrew (another operation or method) screws.

A rule of thumb when you use OOP for problem-solving is that you must always keep in mind that OOP is for modelling the real world, is meant to describe behaviours through a programming language.

Classes

In the real world, we can easily find what we call different types of objects. For instance: cellphones, cars, tools, etc. As you already know, we use those objects for a different types of things. The first one to make phone calls, the second to go from point A to point B, the third one to fix things at home, and so on.

In the illustration below, we can observe different types of real-world objects.

Depending on what type of object you have, is what you can do with the object. For instance, you wouldn’t use a phone as a hammer, or you cannot expect that a plier takes you from point A to point B.

In the real world, we can easily find what we call different types of objects. For instance: cellphones, cars, tools, etc. As you already know, we use those objects for a different types of things. The first one to make phone calls, the second to go from point A to point B, the third one to fix things at home, and so on.

In the illustration on the right, we can observe different types of real-world objects.

Depending on what type of object you have, is what you can do with the object. For instance, you wouldn’t use a phone as a hammer, or you cannot expect that a plier takes you from point A to point B.

In programming, we consider each type of object a Class. From the example, we will have three classes of objects: Tool, Phone and Car.  Notice that it is usual to name the class using the singular, although the class will represent (what you can do with) several objects of the same type.

We will always is define in a class what you can do with an object of that class. So, the class Phone will define (and implement) operations to Call, Send SMS, Browse the internet, etc. The class Car will define operations to Drive, Stop, Signal, etc.

In programming, one way to see a class is as a template to create objects. We define object operations and characteristics in the class.

In programming, we always create an object using a class.

Summary

I presented to you in this article an illustrated guide of some of the most important concepts you should learn as you start learning programming.

If this guide was useful to you, leave a comment below.

H@ppy coding!