Modularity in the Presence of Subclassing
Raymond Paul Stata, John V. Guttag · DSpace@MIT (Massachusetts Institute of Technology) · 1996
Classes are harder to subclass than they need be. This report addresses this problem, showing how to design classes that are more modular and easier to subclass without sacrificing the extensibility that makes subclassing useful to begin with. We argue that a class should have two interfaces, an instance interface used by programmers manipulating instances of the class, and a specialization interface used by programmers building subclasses of the class. Instance interfaces are relatively well understood, but design principles for specialization interfaces are not. In the context of single inheritance, we argue that specialization interfaces should be partitioned into class components. A class component groups part of a class's state together with methods to maintain that state. Class components establish abstraction boundaries within classes, allowing modular replacement of components by subclasses. Achieving this replaceability requires reasoning about each component as an independent...