Child pages
  • re-motion mixins basics -- accessing target class members in a mixin class
Skip to end of metadata
Go to start of metadata

This wiki page is part of the re-motion mixins tutorial.
If you've landed here for the first time and are interested in this subject you will enjoy best results if you start at the beginning: [RM:re-motion mixins]

re-motion mixin provides access to members of the target class with the property This (note the upper-case 'T'), as in

This.SomeTargetClassMethod ()
This.SomeTargetClassProperty ()

Access to base methods of the target class is provided by the property
Base (note the upper-case 'B'), as in

Base.SomeTargetClassMethod () 
Base.SomeTargetClassProperty ()

That This and Base resemble their C# key-word counterparts this and base is no coincidence, of course. They serve analogous purposes.

Neither This nor Base would be visible in our simple mixin classes from the previous sections, because these classes have no base-class.

This and Base must be inherited from the generic
Mixin class. Two versions exists:

  • Mixin<TThis> – one parameter, provides the This property
  • Mixin<TThis, TBase> – two parameters; the first provides the This
    property, the second provides the Base property

In the following illustration, the class QuuxMixin extends the class Foo. Foo has two members named Bar () and Baz. In order to access Foo's Bar () and Baz via This, QuuxMixin must be derived from Mixin<Foo>. In this case, you don't have access to Base, because the single-parameter version of Mixin<> doesn't give you any:

Note that the Foo class is used twice here, in two different roles:

  • the Foo passed to typeof () for the Extends attribute specifies to which class the mixin is applied
  • the Foo passed as type parameter to Mixin<> specifies which members are accessible via This.

A class name as TThis parameter is not the only choice here. The alternative here is to pass an interface for providing members:

For accessing base members overridden by the mixin, you need the Base property, provided by the interface passed as second parameter to Mixin<TThis, TBase>:

Note that you _don't have a choice between class name and interface name for specifying where Base members come from. Only interface names are allowed here.

As you might have noticed, working with Mixin is constrained in various ways:

  • The TThis parameter must be a class name or an interface name
  • The TBase parameter can only be an interface name
  • There is no scheme for getting ONLY Base, only for getting ONLY This
  • You can pass a class name or and interface as TThis parameter, but only an interface as TBase parameter.

These constraints have technical reasons and are not explained in this primer. The rest of this section will refine the concepts presented so far with a more interesting example.

  • No labels