| Henk Verhoeven 2006-08-01, 7:02 pm |
| gavino wrote:
> I dont program yet but smalltalk is the first oo lang
>
> why is oo more powerful and better?
>
Without OO you need to make CASE switch when you need different behavor
depending on some CASEs. If your program gets large, and you design it
properly, you will still end up with many CASE switches repeating the
same CASEs over and over. If you need to add a new CASE, split a CASE in
two, or merge some CASES, you have to go through all your code and
refactor all these CASE switches. OO brings the code for each CASE from
all the switches together in a class. The code from the 'default' cases
end up in their superclass. The case statements are replaced by method
calls. What code is executed depends on the class of the object call is
made on ('polymorphism'). If you need a new CASE, just add a new class,
write it's methods and bring objects (instances) of the new class into
the system. Existing code will behave like new CASEs where added to many
switches, and you did not have to change the calling code. This
mechanism for extension is more flexible and more reliable then CASE
statements, facilitates code-ownership (only modify your own code) but
is not as tricky as function pointers. The facilitation of
code-onwnership makes code reuse easyer. This leads to the availability
of powerfull class libraries and frameworks.
Because the objects also act as data, adding classes also alows one to
add new datatypes and have the data processed by existing code. This
only works where the existing code expects objects. This is why
'primitive' datatypes in hybrid languages are such a nuisance (so
limiting) to OO developers. Because Smalltalk has no primitive
datatypes, it is better (more flexible).
Most Smalltalk dialects further facilitate code-ownership with class
extensions. For some reason most other OO languages put all methods of a
class into a single file. A file is commonly seen as a natural unit of
owned code, resulting in a single owner per class. This prevents one
from adding new methods to existing classes and new polymorphisms to
existing hierarchies, resulting in duplication of classes the same way
CASE switches where duplicated in procedural languages. This makes these
Smalltalk dialects better then most OO languages. (Some languages even
introduced the concepts 'private' and 'final' to prevent calling,
extension, and override withoud modifying other people's code. This
makes these languages even more inferior to Smalltalk ;-) )
Greetings,
Henk Verhoeven,
MetaClass.
|