Smalltalk
From APIDesign
Line 1: | Line 1: | ||
- | Dissatisfied with relational or [[OOP]] mappings of the real world? Let's create our own world inside a computer. Let's write in [[wikipedia::Smalltalk|Smalltalk]]! | + | Dissatisfied with relational or [[OOP]] mappings of the real world? Let's create our own world inside a computer. Let's write in [[wikipedia::Smalltalk|Smalltalk]]! [[Smalltalk]] is unique/strange, but I like [[Smalltalk]]'s [[Hotswap]]. Long time ago [[Smalltalk]] could do things [[Java]] is still [[Hotswap|dreaming about]]. |
- | + | == Extensibility == | |
- | + | The [[Smalltalk]] systems (as far as I remember) start with a bunch of predefined classes which everyone can modify. One can create new subclasses (OK, that is the same in [[Java]]), but one can also add new methods to existing classes. | |
+ | |||
+ | The classical [[Smalltalk]] style to find out what is a type of an object is based on a bunch of '''isSomething''' methods: | ||
+ | |||
+ | <source lang="smalltalk"> | ||
+ | > 1 isNumber | ||
+ | true | ||
+ | > 'text' isNumber | ||
+ | false | ||
+ | > 'text' isString | ||
+ | true | ||
+ | </source> | ||
+ | |||
+ | What people do when they define new types like '''Person'''? They what to have their own '''isPerson''' method. Thus they add this method to '''Object''' to return '''false''' and override it in '''Person''' class to return '''true''': | ||
+ | |||
+ | <source lang="smalltalk"> | ||
+ | > Object subclass: #Person | ||
+ | > !Object methodsFor: 'Checking Person'! isPerson ^false !! | ||
+ | > !Person methodsFor: 'Checking Person'! isPerson ^true !! | ||
+ | </source> | ||
+ | |||
+ | One can then easily check on any object if it is a person or not: | ||
+ | |||
+ | <source lang="smalltalk"> | ||
+ | > 1 isPerson | ||
+ | false | ||
+ | > Person new isPerson | ||
+ | true | ||
+ | </source> | ||
+ | |||
+ | As a result, if you want to understand a [[Smalltalk]] program, you should look at the added '''isSomething''' methods in the '''Object'''. This kind of programming creates not [[OOP|object oriented systems]], but different flavors (in the above case a ''person oriented system''), where capabilities of each object are driven by the variety of subclasses. | ||
+ | |||
+ | I don't like that each [[Smalltalk]] system ends up being completely unique. This is not how [[API]]s should be designed, as that prevents merge of systems developed independently, as far as I can tell. | ||
+ | |||
+ | == Is [[Java]] an [[OOP]] system? == | ||
+ | |||
+ | But enough about [[Smalltalk]] and let's look at [[Java]]'s root class {{JDK|java/lang|Object}}. Can you guess what kind of ''oriented system'' [[Java]] is? | ||
+ | |||
+ | <comments/> | ||
+ | |||
+ | [[TBD]] |
Revision as of 17:51, 12 July 2011
Dissatisfied with relational or OOP mappings of the real world? Let's create our own world inside a computer. Let's write in Smalltalk! Smalltalk is unique/strange, but I like Smalltalk's Hotswap. Long time ago Smalltalk could do things Java is still dreaming about.
Extensibility
The Smalltalk systems (as far as I remember) start with a bunch of predefined classes which everyone can modify. One can create new subclasses (OK, that is the same in Java), but one can also add new methods to existing classes.
The classical Smalltalk style to find out what is a type of an object is based on a bunch of isSomething methods:
> 1 isNumber true > 'text' isNumber false > 'text' isString true
What people do when they define new types like Person? They what to have their own isPerson method. Thus they add this method to Object to return false and override it in Person class to return true:
> Object subclass: #Person > !Object methodsFor: 'Checking Person'! isPerson ^false !! > !Person methodsFor: 'Checking Person'! isPerson ^true !!
One can then easily check on any object if it is a person or not:
> 1 isPerson false > Person new isPerson true
As a result, if you want to understand a Smalltalk program, you should look at the added isSomething methods in the Object. This kind of programming creates not object oriented systems, but different flavors (in the above case a person oriented system), where capabilities of each object are driven by the variety of subclasses.
I don't like that each Smalltalk system ends up being completely unique. This is not how APIs should be designed, as that prevents merge of systems developed independently, as far as I can tell.
Is Java an OOP system?
But enough about Smalltalk and let's look at Java's root class Object. Can you guess what kind of oriented system Java is?
<comments/>