Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

re-motion

...

mixin

...

provides

...

access

...

to

...

members

...

of

...

the

...

target

...

class

...

with

...

the

...

property

...

This

...

(note

...

the

...

upper-case

...

'T'),

...

as

...

in

...

}
Code Block
This.SomeTargetClassMethod ()
This.SomeTargetClassProperty ()
{code}

Access

...

to

...

base

...

methods

...

of

...

the

...

target

...

class

...

is

...

provided

...

by

...

the

...

property

...


Base (note

...

the

...

upper-case

...

'B'),

...

as

...

in

...

}
Code Block
Base.SomeTargetClassMethod () 
Base.SomeTargetClassProperty ()
{code}

That {{This}} and {{Base}} resemble their C# 

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:

Image Added

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:

Image Added

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>:

Image Added

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.