4.1. Generalization and Specialization

If you are lucky, you are part of a programming team that places a premium on design. You know that a good design results in lower software development costs over time, which ultimately means a paycheck for you. Good programmers know that the cost of writing software cannot outweigh the benefit it yields; you must be profitable. A good design is critical. Fortunately, a perfect initial design is not critical. In fact, perfection rarely occurs, if it happens at all. A good design is arrived at over time.

Usually, after running headfirst into the code and writing several classes, you begin to see patterns. You might notice that several classes share the same kind of data and exhibit the same behavior. You might find that you can group this data and behavior into one class. This scenario is called generalization. Usually, generalizations are discovered after the fact—the derived classes are written first and the base class is determined last. You can think of this process, refactoring, as retroactive OOP.

Refactoring is somewhat contrary to the idea of specialization, in which class hierarchies are derived over several versions of an application to handle special cases. For example, in Version 1.0 of your application, Employee might have been sufficient to handle all company employees. Over time, though, it became necessary to create derived classes based on Employee to handle the following new situations that did not exist when the application ...

Get Object-Oriented Programming with Visual Basic .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.