Re: C or C++?
Gianni Mariani wrote:
I don't think it supports the previous posters argument that OOP
requires polymorphism. I'm no OOP crtitic so I don't know if there is
anything wrong with it if it smacked me in the head.
This question is a book unto itself. OO _should_ be defined so its
root principle is polymorphism, but the term OO is too abused for
WikiPedia to arbitrate any consensus.
One Robert C Martin says it best (IIRC): "Structured programming is
discipline imposed upon direct transfer of control flow. OO
programming is discipline imposed upon indirect transfer of control
flow."
By "discipline" he means that the statement if(foo){ int bar = 42; }
will refuse to compile that 'bar' outside its block {}. That is
Structured Programming - matching the scopes of variables to branches
of control flow.
In a structural paradigm, you can call methods indirectly, achieving
polymorphism, in one of two ways. You can write a 'switch' statement
that reads a type code, and branches to each target type, or you can
use a function pointer. Both systems suck, because to add another type
you must add a case to every matching switch statement, and to use a
function pointer you must generally assign the pointer, possibly
typecast it to call it, possibly check it for NULL, etc. All this
cruft raises the cost of polymorphism.
An OO language fixes this by merging the switch and function pointer
into a secret jump table. The language will typesafely manage the jump
table for you, mostly at compile time. That allows programmers to
impose discipline on how they partition a program into polymorphic
code blocks. And, once again, the compiler helps match variable scope
to code block scope. Objects are variables bound to polymorphic
behavior behind typesafe interfaces.
--
Phlip