Child pages
  • under the hood of re-motion mixins -- mixins based on 'Mixin-TThis'
Skip to end of metadata
Go to start of metadata

The wiki page

re-motion mixins basics -- the generic 'Mixin' type

uses the parrot/phone example for illustrating the use of the generic Mixin<TThis> type. Here is the example as UML. It is not much different from the previous example (Pretend is actually called PretendToTalkOnThePhone):

The next illustration shows what re-motion mixins makes from that:

Note that the [OverrideTarget] attribute has no influence on the layout of such an UML diagram. [OverrideTarget] attributes only have influence on how the methods in the generated class are fleshed out.

The previous example showed that mixin[0] in the instance of the derived class references an instance of the mixin class. The illustration shows that the This member variable in the mixin class instance points back to an instance of the _derived class.

Again, whether the mixin class extends the target class or the target class uses the mixin class is irrelevant for how classes are laid out.

Target method overrides mixin method

If a target method overrides a mixin method, we need a specialized sub-class of the mixin class where the overridden method delegates to the method in the target class. The UML diagram for the setup generated by re-motion mixins for overriding mixin methods looks very similar to the one above, only the sub-class of the mixin class (OnThePhoneMixin_Mixin_SOM3GUID) has been added for overriding:

Note the red dotted line. The _mixin[0] in the derived class Parrot_Mixed_SOM3GUID still is of type OnThePhoneMixin, but at run-time an instance of the sub-class OnThePhoneMixin_SOM3GUID is stored in _mixin[0].

The overridden method Say in the generated OnThePhoneMixin_Mixin_SOM3GUID class requires the This property in order to access the target class' Say method:

// in 'OnThePhoneMixin_SOM3GUID':
public override void Say (string whatToSay)
{
    This.Say (whatToSay);
}

Since the This property is only available in mixin classes derived from Mixin<>, you MUST derive your mixin class from Mixin<> if you want your target class to override methods in the mixin class.

This is the simple reason behind the fact that you must derive your mixin from Mixin<> if you want to enable overriding of mixin methods by target methods.

  • No labels