30 Reusable designs
The last chapter illustrated some simple uses of inheritance and polymorphism. It
is these programming techniques that distinguish "Object Oriented Programming"
from the "object based" (or abstract data type) style that was the main focus of Part
IV of this text. These Object Oriented (OO) techniques originated in work on
computer simulation of real world systems. The "dungeon game" is a simulation
(of an unreal world) and so OO programming techniques are well suited to its
Although OO programming techniques were originally viewed as primarily
applicable to simulations, they have over the last ten years become much more
widely utilised. This greater use is largely a consequence of the increased
opportunity for "reuse" that OO techniques bring to application development.
Reuse, whether of functions, components, or partial designs, always enhances
productivity. If you can exploit reusable parts to handle "standard" aspects of an
application, you can focus your efforts on the unique aspects of the new program.
You will produce a better program, and you will get it working sooner than if you
have to implement everything from scratch.
Approaches to Reuse
If you are using the "top down functional decomposition" strategy that was
illustrated in Part III, you are limited to reusing standard algorithms; the code in the
function libraries implements these standard algorithms. Reusing algorithms is
better than starting from scratch. These days, nobody writes their own sin()
function, they use the version in the maths library. Computer science students are
often made to rewrite the standard sorting and searching functions, but
professionals use qsort() and bsearch() (standardized sort and binary search
functions that are available in almost every development environment). As noted in
Chapter 13, over the years huge libraries of functions have been built up,
particularly in science and engineering, to perform standard calculations.
Reuse with functions