首页> 外文期刊>Computer Languages, Systems & Structures >Safe metaclass composition using mixin-based inheritance
【24h】

Safe metaclass composition using mixin-based inheritance

机译:使用基于Mixin的继承进行安全的元类组合

获取原文
获取原文并翻译 | 示例

摘要

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.
机译:在元编程和反射语言的上下文中,类被视为成熟的对象,它们是名为metaclasses的其他类的实例。事实证明,元类对于定义新的类属性很有用。此类属性的示例是惰性内存分配,具有单个实例的多重继承。通过实例化实现所需属性的元类来获得具有某些属性的类。但是,实例化仅允许将由单个元类定义的属性分配给类。需要一种组合机制来重用由不同的元类定义的属性并将它们分配给给定的类。在不破坏类-元类兼容性的情况下执行此组合。当类耦合到其元类时,就会出现兼容性问题。因此,在编写元类时,我们需要注意这种耦合以避免运行时异常。在本文中,我们探索了使用基于混合的继承来执行元类组合。基于混合的继承是单继承和多继承的有趣替代。与单一继承相反,它允许在不同的类层次结构之间重用代码。与多重继承相反,它允许开发人员通过显式线性化来显式指定所需的行为。我们的建议是通过在元类级别引入mixin来定义和组合可重用的类属性。我们证明了可以在不更改兼容性的情况下有效完成此介绍。

著录项

相似文献

  • 外文文献
  • 中文文献
  • 专利
获取原文

客服邮箱:kefu@zhangqiaokeyan.com

京公网安备:11010802029741号 ICP备案号:京ICP备15016152号-6 六维联合信息科技 (北京) 有限公司©版权所有
  • 客服微信

  • 服务号