Safe metaclass composition using mixin-based inheritance

  • Authors:
  • Noury Bouraqadi

  • Affiliations:
  • Dépt. G.I.P., Ecole des Mines de Douai, 941, rue Charles Bourseul, B.P. 838, Douai Cedex 59508, France

  • Venue:
  • Computer Languages, Systems and Structures
  • Year:
  • 2004

Quantified Score

Hi-index 0.00

Visualization

Abstract

In the context of meta-programming and reflective languages, classes are treated as full-fledged objects which are instances of other classes named metaclasses. Metaclasses have proved to be useful for defining 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 defined by a single metaclass. A composition mechanism is needed to reuse properties defined by different 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 different class hierarchies. Contrary to multiple inheritance, it allows developers to explicitly specify the desired behavior through explicit linearizations. Our proposal is to define and compose reusable class properties by introducing mixins at the metaclass level. We demonstrate that this introduction can be done efficiently without altering compatibility.