Safe metaclass composition using mixin-based inheritance
✍ Scribed by Noury Bouraqadi
- Book ID
- 104011826
- Publisher
- Elsevier Science
- Year
- 2004
- Tongue
- English
- Weight
- 254 KB
- Volume
- 30
- Category
- Article
- ISSN
- 1477-8424
No coin nor oath required. For personal study only.
✦ Synopsis
In the context of meta-programming and re ective languages, classes are treated as full-edged objects which are instances of other classes named metaclasses. Metaclasses have proved to be useful for deÿning new class properties. Examples of such properties are lazy memory allocation, multiple inheritance, having a single instance. A class with some property is obtained by instantiating a metaclass which implements the desired property. However, instantiation allows assigning to a class only properties deÿned by a single metaclass. A composition mechanism is needed to reuse properties deÿned by di erent metaclasses and assign them to a given class. This composition should be performed without breaking class-metaclass compatibility. The compatibility issue arises when a class is coupled to its metaclass. So, when composing metaclasses, we need to take care of such coupling to avoid run-time exceptions.
In this paper, we explore the use of mixin-based inheritance to perform metaclass composition. Mixin-based inheritance is an interesting alternative to both single and multiple inheritance. As opposite to single inheritance, it allows reusing code among di erent class hierarchies. Contrary to multiple inheritance, it allows developers to explicitly specify the desired behavior through explicit linearizations. Our proposal is to deÿne and compose reusable class properties by introducing mixins at the metaclass level. We demonstrate that this introduction can be done e ciently without altering compatibility.