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
propertyMixin<TThis, TBase>
– two parameters; the first provides the This
Base
propertyIn 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:
Foo
passed to typeof ()
for the Extends
attribute specifies to which class the mixin is appliedFoo
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:
TThis
parameter must be a class name or an interface nameTBase
parameter can only be an interface nameBase
, only for getting ONLY This
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.