Popis: |
Classes are often too small units of modularization. In a lot of cases, a cohesive piece of functionality involves a group of related classes. Although mainstream languages provide class grouping mechanisms, such as packages and inner classes in Java, the typical object-oriented techniques, such as inheritance and subtype polymorphism, are not supported at the scope of such class groups. As a result, variations involving multiple classes must be encoded by variations of individual classes. Such encodings compromise type-safety and produce a considerable amount of glue code, which is often error-prone and not stable. The main statement of this thesis is that by making typical object-oriented techniques available at the scope of a group of classes we can provide a better support for managing variations at that scope. For the purpose of making inheritance and polymorphism available for a group of classes, we rely on the ideas of virtual classes and family polymorphism. A large-scale multiple inheritance is enabled by the propagating mixin composition. In this thesis we present the first implementation of these ideas for Java, and propose improvements to their semantics, namely a more intuitive linearization algorithm for propagating mixin composition and more flexible path-dependent types. We also introduce abstract virtual classes, which increase the advantages of family polymorphism by providing the possibility to describe interfaces for families of classes. Further, we propose a novel concept of dependent classes, which enhances virtual classes in analogous way like multimethods enhance single-dispatch. The multi-dispatch for classes not only enables dispatch of their functionality by multiple constructor parameters, but also generalizes family polymorphism with the possibility to express membership of an object in multiple families. The feasibility of the new concept is validated in two ways. First, we design a concrete language with dependent classes, called DepJ, and implement a type-checker and interpreter for it. Second, we formalize the features of dependent classes in vc^n and DC_C calculi, and verify their soundness and decidability. The expected advantages of virtual classes and dependent classes for variation management are validated by a set of variation scenarios. We explore variations at the scope of individual objects, as well as at the scope of a group of objects. We also investigate interactions of different kinds of variations and analyze specific variation scenarios in the context of object-oriented frameworks. We identify the problems of implementing these scenarios using conventional object-oriented techniques, and show that these problems are resolved by implementations with the advanced techniques. In particular, we show that virtual classes and propagating-mixin composition provide the typical advantages of inheritance for managing variations of a group of objects. Dependent classes provide the typical advantages of multi-dispatch for managing variations of a class. They also generalize the advantages of virtual classes with the possibility to modularize variations of multiple overlapping groups of objects, and provide a better solution for modelling multiple variations of a group of objects. |