articles/oop.md: update article

This commit is contained in:
tocariimaa 2025-03-08 15:14:04 -03:00
parent bf53e67b79
commit 50d8849913

View file

@ -1,12 +1,13 @@
# Object Oriented Programming
Also known by its acronym OOP (**POO** in Spanish for *Programación Orientada a Objectos*) is a programming paradigm.
Also known by its acronym OOP (**POO** in Spanish for *Programación Orientada a Objetos*) is a programming paradigm.
OOP is split between two "schools" of design: Simula-style OOP and [Smalltalk](smalltalk.md)-style OOP.
TODO
## Simula-style OOP
Most popular languages that have OOP have it in the Simula form. Some of these languages are:
Most popular languages that have OOP have it in the Simula form, so when the term OOP is used, one always means this kind of OOP.
Some of these languages are:
- [C++](cpp.md)
- [Java](java.md)
- [JavaScript](javascript.md)
@ -15,7 +16,20 @@ Most popular languages that have OOP have it in the Simula form. Some of these l
## Smalltalk-style OOP (message passing)
In Smalltalk-style OOP, objects communicate with each other by means of message passing. This
allows for greater dynamism, something that on Simula-style OOP can be archived with virtual methods.
allows for greater dynamism. Unlike in Simula-style OOP, objects can receive any message and its
up to the object whether to reply or raise an error if it doesn't understand the message.
For example, in Smalltalk if I have an object `x`, I can send messages to it and it will reply
with an answer:
```st
| x |
x := 39.
"Are you `nil`?"
x isNil. "==> false"
"Messages can carry a payload of course:"
"Are you a number?"
x isKindOf: Number. "==> true"
```
Some languages based on or inspired by Smalltalk-style OOP are:
- Objective-C: some [C](c.md)-Smalltalk chimera; similar to C++ but using message passing instead of method calling.