Child pages
  • An ACTING LESSON for your pet parrot -- working with 'Base'
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]

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.

If you run the client code

// 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 ();

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
  • No labels