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. 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 by subclasses. Replaceability requires reasoning about each component as an independent unit that depends only on the specifications of other components and not on their implementations. We discuss rules for such reasoning. In the context of multiple inheritance, we advocate the use of mixins as a replacement for class components. Instantiable classes are built by combining multiple mixins. In the mixin style of design, class hierarchies have more classes than in equivalent single-inheritance designs, but the classes have smaller, simpler interfaces and can be reused more flexibly. To explore the impact our ideas might have on program design, we consider existing libraries in light of the proposed single- and multiple-inheritance methodologies. We also consider the impact of our ideas on language design.
Report Downloads
Cited By
- Parkinson M and Bierman G Separation logic and abstraction Proceedings of the 32nd ACM SIGPLAN-SIGACT symposium on Principles of programming languages, (247-258)
- Parkinson M and Bierman G (2019). Separation logic and abstraction, ACM SIGPLAN Notices, 40:1, (247-258), Online publication date: 12-Jan-2005.
- Banerjee A and Naumann D (2005). Ownership confinement ensures representation independence for object-oriented programs, Journal of the ACM (JACM), 52:6, (894-960), Online publication date: 1-Nov-2005.
- McCamant S and Ernst M Predicting problems caused by component upgrades Proceedings of the 9th European software engineering conference held jointly with 11th ACM SIGSOFT international symposium on Foundations of software engineering, (287-296)
- McCamant S and Ernst M (2003). Predicting problems caused by component upgrades, ACM SIGSOFT Software Engineering Notes, 28:5, (287-296), Online publication date: 1-Sep-2003.
- Ruby C and Leavens G Safely creating correct subclasses without seeing superclass code Proceedings of the 15th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications, (208-228)
- Ruby C and Leavens G (2019). Safely creating correct subclasses without seeing superclass code, ACM SIGPLAN Notices, 35:10, (208-228), Online publication date: 1-Oct-2000.
- Leino K Data groups Proceedings of the 13th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications, (144-153)
- Leino K (2019). Data groups, ACM SIGPLAN Notices, 33:10, (144-153), Online publication date: 1-Oct-1998.
Recommendations
Modular reasoning in the presence of subclassing
OOPSLA '95: Proceedings of the tenth annual conference on Object-oriented programming systems, languages, and applicationsConsiderable progress has been made in understanding how to use subtyping in a way that facilitates modular reasoning. However, using subclassing in a way that facilitates modular reasoning is not well understood. Often methods must be overriden as a ...
Modular reasoning in the presence of subclassing
Considerable progress has been made in understanding how to use subtyping in a way that facilitates modular reasoning. However, using subclassing in a way that facilitates modular reasoning is not well understood. Often methods must be overriden as a ...