articles/oop.md: update article
This commit is contained in:
parent
bf53e67b79
commit
50d8849913
1 changed files with 17 additions and 3 deletions
|
@ -1,12 +1,13 @@
|
||||||
# Object Oriented Programming
|
# 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.
|
OOP is split between two "schools" of design: Simula-style OOP and [Smalltalk](smalltalk.md)-style OOP.
|
||||||
|
|
||||||
TODO
|
TODO
|
||||||
|
|
||||||
## Simula-style OOP
|
## 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)
|
- [C++](cpp.md)
|
||||||
- [Java](java.md)
|
- [Java](java.md)
|
||||||
- [JavaScript](javascript.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)
|
## Smalltalk-style OOP (message passing)
|
||||||
In Smalltalk-style OOP, objects communicate with each other by means of message passing. This
|
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:
|
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.
|
- Objective-C: some [C](c.md)-Smalltalk chimera; similar to C++ but using message passing instead of method calling.
|
||||||
|
|
Loading…
Add table
Reference in a new issue