You're asking who? Some disagree .
How many and what are the pillars of object-oriented programming?
Most of the available literature cites four, the three that are more or less universal are:
-
Inheritance
Is the ability of an object to be idealized based on another object
-
Polymorphism
It is the ability of one object to pass through another under certain circumstances, as long as they are compatible
-
Encapsulation
It is the object's ability to hide implementation details by exposing only what is publicly accessible
Most still accept abstraction which is the ability to express something in general terms, without a specificity, isolated from what does not matter in that context. Not everyone agrees because it seems to be just the sum of encapsulation and polymorphism. Others say it's a bit different. It is true that the first three are very concrete mechanisms and the abstraction is not so much, so it makes some sense.
Some people think that having a abstract
in language is abstraction, but not quite so. This helps, the interface is still an abstraction, but the mechanism itself is inheritance or polymorphism.
At a more conceptual point the abstraction is closer to the encapsulation since the abstraction is to hide the concrete mechanism, it is to hide the detail of the implementation.
Some still cite some other mechanisms like operator overload, but some say that this is just the polymorphism with abstraction and who knows the encapsulation.
I've seen other mechanisms being cited, but it's a lot rarer.
My understanding is that these main mechanisms must be present, all of them, to say that it is object oriented. When only one or two of them are present the code is valid for other paradigms. And I always found the fundamental inheritance. Just encapsulating and leaving polymorphic exists in other paradigms.
Other Object Orientation Settings
There is more conceptual literature, often speaking more about object-oriented design , which does not even consider such mechanisms. Some are vague and leave room for interpretation. These literatures do not focus on the reuse of code, on the abstraction of the real world in code, on the facilities of languages, on mechanisms.
There are even those who define object orientation as putting the object as focus and the most obvious mechanism of this is you say who the object is and then indicate what you want to do with it, that is, print(objeto)
is not OOP, objeto.print()
is. I think it's too simple and too vague.
How do these pillars relate?
They do not need to have a direct relationship, but they can. All inheritance involves subtype, and the most traditional polymorphism has to do with subtype. There is inheritance without doing subtype, but it is not common, I do not remember a case. It is possible to subtype even without inheritance. Many languages that are not considered object-oriented do this. There is no inheritance to say that it is OO.
Encapsulation is something much more orthogonal, it is not necessary for other concepts and it does not depend on others to exist. In fact even primitive languages have some form of encapsulation, although not so powerful and simple to use. Encapsulation, which some claim to be the most important of OOP, exists in many other paradigms, so if that's the important thing people could use other paradigms and stop that fixation with OO.
It is complicated to have abstraction without encapsulation and polymorphism, but it is possible. Unless you're talking about abstraction in general , it's very simple there, but I understand that in OO the concept has a more strict definition.
Are they the same for all languages that support Object Orientation?
One thing I've said before and I'll repeat, programming object-oriented has nothing to do with languages. It is true that some provide facilities for programming OO, but this is not mandatory, so these pillars exist for the code to be object oriented, if the language has facilitative mechanisms and you do not use them, or if the language lacks the facilitators, but uses the abutments is what defines whether the code is object oriented or not.
I have already answered a much more detailed question on the subject . And I get the impression that it's even duplicate.