Next: Object-Oriented Terminology, Previous: Object-oriented Forth, Up: Object-oriented Forth
Often we have to deal with several data structures (objects),
that have to be treated similarly in some respects, but differently in
others. Graphical objects are the textbook example: circles, triangles,
dinosaurs, icons, and others, and we may want to add more during program
development. We want to apply some operations to any graphical object,
draw for displaying it on the screen. However,
has to do something different for every kind of object.
We could implement
draw as a big
control structure that executes the appropriate code depending on the
kind of object to be drawn. This would be not be very elegant, and,
moreover, we would have to change
draw every time we add
a new kind of graphical object (say, a spaceship).
What we would rather do is: When defining spaceships, we would tell
the system: “Here's how you
draw a spaceship; you figure
out the rest”.
This is the problem that all systems solve that (rightfully) call themselves object-oriented; the object-oriented packages presented here solve this problem (and not much else).