Why Reusable Base Classes Are Difficult to Write
In a normal application, you write code for software components that solve particular problems. It's usually a simple matter of meeting the project specification. With reusable base classes, however, you must anticipate future programming needs, both your own and those of others. You have to write a class that is general and complete yet efficient and easy to use.This chapter's example shows the difficulty of building reusable software. The class was originally intended to be a frame class that would "remember" its window size and position. In addition to remembering their window sizes, many existing Windows-based programs also remember whether they've been minimized to the taskbar or whether they've been maximized to full screen. Then there is the oddball case of a window that is both minimized and maximized. In addition, the frame class needs to manage the toolbar and the status bar, and the class has to work in a dynamic-link library (DLL). In short, it's surprisingly difficult to write a frame class that would do everything that a programmer might expect.
In a production programming environment, reusable base classes might fall out of the normal software development cycle. A class written for one project might be extracted and further generalized for another project. There's always the temptation, though, to cut and paste existing classes without asking, "What can I factor out into a base class?" If you're in the software business for the long term, it's beneficial to start building your library of truly reusable components.