In this section we are going to talk about the object-oriented programming paradigm (POO in Spanish, OOP in English).
This is a very useful tool that will help us build intuitive solutions for our programs or video games.
What is object-oriented programming?
It is an intuitive way of thinking about the problems we have to solve.
When using POO, we think about which objects we should build so that they receive input information, process it and produce output information.
Objects are abstract entities that we will create taking into account the way they must work, what are their basic characteristics, what are their responsibilities, with whom they must relate, among other factors.
Articles on object-oriented programming
Before we go any further I will leave a list of all the articles I am creating on this topic.
In this article I explain what a class is in programming and give some examples of classes in C# language at Unity.
In this article I propose a practical exercise on programming classes. We make class diagrams and implement them in Unity in C# language.
Features of Object-Oriented Programming
I will try to explain with my words what some of the great concepts that appear when studying OOP mean.
Abstraction is a process of our intellect that allows us to take an object of study, relieve the fundamental characteristics or traits and create a mental idea of that object.
From this mental idea we will create our programming objects.
This feature implies that all the data and functions of the object we want to model will be gathered or encapsulated in the same entity.
In practice we are going to encapsulate the data and functions that an object will have within a programming class.
Inheritance enables you to establish a class structure organized in hierarchies.
In upper classes (known as super classes), properties and general behavior are defined and daughter classes (subclasses) are created that inherit the properties and behavior of the super class.
Through inheritance, more and more specific classes can be built, but they have characteristics in common among them since they descend from the same super class.
Polymorphism allows us to take a set of objects of a different type and execute one or more methods that they all understand, but the function that this method executes will be specific to each type of object.
This allows us to create different types of objects that respond differently to the same stimulus.
This in my opinion is one of the most powerful concepts of the OOP.
Principle of information hiding
This property has to do with the data and functions that are considered internal to an object. These properties must be hidden from the outside to prevent other objects from manipulating them directly.
The objects will offer to the outside a series of public functions to make use of their functionality and access or modify their internal data.