Versions Compared

Key

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

...

What

...

if

...

we

...

want

...

a

...

really

...

professional

...

stage

...

animal

...

for

...

theatrical

...

performance?

...

Then

...

it

...

is

...

important

...

to

...

speak

...

LOUD

...

all

...

uppercase,

...

that

...

is.

...

We

...

implement

...

LOUD

...

by

...

overriding

...

the

...

Say

...

()

...

method

...

and

...

uppercasing

...

the

...

argument

...

string

...

s

...

.

...

This

...

in

...

turn

...

requires

...

access

...

to

...

the

...

base

...

method

...

in

...

the

...

mixin

...

– enter Base.

In contrast to the TThis parameter introduced in the previous section, you can't use a class for the TBase parameter, you MUST use an interface at run-time.

Right: Mixin<Parrot, IParrot> or Mixin<IParrot, IParrot>
Wrong: Mixin<Parrot, Parrot> or Mixin<IParrot, Parrot>

For the following implementation

  • we override the Parrot's (or IParrot's, respectively) Say method with one that uppercases the string s and calls the overridden (base) method with that LOUD string
  • we make the Parrot's Say method virtual, so that it can be overridden
  • we access the base Say () via the Base property – Base.Say ()
  • the Base property is provided by the interface IParrot as parameter for TBase

Here is an illustration.

Image Added

If you run the client code

Code Block
// Don't forget the popsicle to prop up the 'Remotion' assembly
var t = typeof (IMixinTarget);

var myPetParrot = ObjectFactory.Create<Parrot> (ParamList.Empty);
((IOnThePhoneMixin) myPetParrot).PretendToTalkOnThePhone ();
{code}

the

...

output

...

will

...

look

...

like

...

this:

...

Output

Method called

"RING RING"

Say ()

"RING RING"

Say ()

"HALLOHO?"

Say ()

"OH! HI!"

This.Say ()

"I'm fine! And yourself?"

Base.Say ()

"Glad to hear that! I love you! Bye!"

Base.Say ()

Sample code

The sample code for this exercise is located in subversion.

Under the hood

...