Section 10.5. MIXIN PROGRAMMING SUPPORT


10.5. MIXIN PROGRAMMING SUPPORT

In addition to the implicit This type parameter described in Section 10.3.4, JL introduces three other language features and one compiler feature that make mixin programming more effective [12]. In this section, we briefly characterize two language features that have been implemented in JL.

10.5.1. Constructor Propagation

Superclass initialization is not straightforward in mixin classes, because the superclass of a mixin is not known when the mixin is defined [37]. To make constructors convenient to use with mixins, JL introduces the propagate modifier for constructors. Constructors are propagated from parent to child class, with constructors marked propagate in the parent only able to affect constructors marked propagate in the child. (The default constructor in a child class is also considered propagatable.) Constructor propagation is more than the simple inheritance of constructors, because constructor signatures and bodies can change when constructors are propagated to child classes.

In Fidget, one measure of the effectiveness of automatic constructor propagation is that many constructors do not need to be hand-coded. In BaseFidget, 20 constructors are declared with propagate. On average, the 13 kernel layers that extend BaseFidget declare just over one constructor each, which indicates that automatic constructor generation is sufficient in most cases.

10.5.2. Deep Conformance

Mixins provide a powerful way to compose software, but to avoid composing incompatible features, mechanisms are needed to restrict how mixins are used. Type parameter constraints are one mechanism for restricting the use of mixins to avoid incompatibilities. In addition, JL extends the semantics of constrained type parameters to work with the nested structure of mixin layers.

JL's notion of deep interface conformance [27] extends Java's idea of interface constraints to include nested interfaces. Normally, a Java class that implements an interface is not required to implement the interface's nested interfaces. JL introduces the deeply modifier on implements clauses to require classes to implement the nested interfaces of the classes' super-interfaces. In addition, by using the deeply modifier on extends clauses, JL also defines deep subtyping [27]. Deep subtyping requires that a subtype have the same nested structure as the supertype it extends.

In JL, mixin layers that deeply conform to the same interface or mixin layers that deeply subtype the same supertype can be composed with each other, because they are compatible at all nesting levels. This compatibility is guaranteed by the compiler.



Aspect-Oriented Software Development
Aspect-Oriented Software Development with Use Cases
ISBN: 0321268881
EAN: 2147483647
Year: 2003
Pages: 307

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net