ObjectOriented
Hi Peter
At this point, may I jump in and say that while OOP may display a lot of
commonality with modular and structured programming, it is much more than that,
and it is a (common) mistake to use it simply as a neat modular technique. As
you say, that alone is not too much, but persevere, there be hidden treasure
here! I think you will enjoy learning Smalltalk. It is the fist language I
used when I started in OOP, and I am glad I did so.
What I found happened to me, was a period of about two months of headbanging as
I tried to force my old style into OOP (it wouldn't go) and then a slow but
steady period of illumination as I started to "click" into the idea of mapping
the real world onto the objects. In this sense every OOP program is an
(elegant – hopefully) simulator.
The OOP features which you mention are OK, but they are not what is now
commonly called OOP – i.e. encapsulation, etc. tend to be called Object-Based
programming these days, and are only a subset of OOP. The main OOP feature is
INHERITTANCE, which allows you to build a hierarchy of classes starting from
the most general, and then specialising, keeping what you need from the
"parents". This is NOT the hierarchy of the components of your program, but
the hierarchy of their structure! (Not unlike the Linnaen hierarchy used to
classify living things according, to phullum,class,genus,family etc.) The best
book I have found on this is Booch's "Object-Oriented Analysis and Design –
with Applications") You can also learn a lot about OOP by studying the Amiga
Exec!
I also think you misunderstood polymorphism. What you are describing, I think,
is operator overloading, which is permitted in C++, although it is almost never
used, unless you are designing a new module sub-language (and then it is
brilliant).
Polymorphism in C++ allows you to give a pointer to a common parent class,e.g.
Vehicle, and then send a message to that class, e.g. Move(). Then the vehicle
will move according to its internal specification, e.g. a car will drive, a
boat will sail, a plane will fly, etc. This reduces the necessity for C
structs like unions. Pollymorphic code is executed by examining the pointer
type at run-time, and so, in a way, it is interpretted. This introduces a great
deal of programming flexibility, with little overhead.
All the best in your OOP endeavours
Alex