Code Reuse

Most applications developed today are essentially built from scratch. Over and over, we recreate many of the same processes and procedures from earlier programs. Granted, many programmers copy code from existing programs into their new programs, and then modify the copied code to fit any new requirements. But this means that the same code is copied over and over again. If we need to change something in the original code, we'll also have to find and change that same code everywhere it's been used. Which is far from ideal.

You've probably done this type of code reuse many times over. And you've probably spent countless hours going through dozens of programs making the same code change. Then you've spent hours debugging all the changed programs. Talk about expensive!

In other situations, code reuse is managed through libraries of code, or maybe even precompiled routines. But even in these cases, code reuse is difficult. In one of the best environments I've ever worked, we had a large and complete library of precompiled routines. By using these routines, we were able to dramatically improve the productivity of our development team.

Still, it wasn't uncommon to run into a program that required a change to our library. Unfortunately, a change to the library required modifying and rebuilding all the applications that relied on the library. Worse yet, sometimes the new functionality required actually going back and changing all the programs that used the library to bring them up to date. This was expensive, and required us to modify what was otherwise stable program code, thereby increasing the risk of bugs.

So copying code helps, but it's far from ideal. Creating libraries of code, or pre-compiled routines, can help a lot; but both techniques still leave a lot to be desired. What we really need is a solution that allows code reuse yet retains the flexibility of selective changes based on the need of the particular application. It would be great if we could derive what we needed and modify or extend the behavior. Fortunately, objects provide just this capability.