Versions Compared

Key

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

...

As soon as TBase enters the picture, we face a complication, because then the mixed class ("Parrot_Mixed_SOM3GUID") can have two versions of each target method:

  • the one overridden by the mixin class (e.g. Say (string s)
  • the original method from the target class (that would be Base.Say (string s) when seen from the mixin class)

Now look at this code snippet:

...

The most important points in the diagram are:

  • OnThePhoneMixin holds a reference to Parrot_BaseCallProxy_SOM3GUID (labeled "Parrot_BaseCallProxy..." in the illustration) in Base
  • Parrot_BaseCallProxy_SOM3GUID holds a reference to the mixed class Parrot_Mixed_SOM3GUID (labeled "Parrot_SOM3GUID")
  • Parrot_BaseCallProxy_SOM3GUID implements IParrot (note that, in this diagram, Parrot or Parrot_Mixed_SOM3GUID do not}}
  • Parrot_Mixed_SOM3GUID has been endowed with a Base_Say method

A call OnThePhoneMixin's PretendToTalkOnThePhone () to Base.Say will eventually call Parrot's Say (). Here is a walk-through for how this works.

  • Base.Say ("Halloh?") delegates to the Say () method in Parrot_BaseCallProxy_SOM3GUID
  • Parrot_BaseCallProxy_SOM3GUID's Say () method delegates to Base_Say () in Parrot_Mixed_SOM3GUID
  • Parrot_Mixed_SOM3GUID's Say () delegates to Parrot's Say () via base.Say () (note the lowercase 'b' in base.Say () – not a typo; Parrot_Mixed_SOM3GUID calls its base-class' Say ()

Why can't Parrot_Mixed_SOM3GUID's own Say () method be called here? Simple: that's the Say () overridden by the mixin class – the one called by This.Say ().

...

Note that the construction of the two implementor classes works differently for each interface if you pass TWO interfaces to Mixin<TThis, TBase>, as in Mixin<IParrot, IParrot>, for example. This call is equivalent to Mixin<Parrot, IParrot>, because re-motion mixin is smart enough to do the right thing here:

  • for the first IParrot, the object factory finds Parrot as the implementor and subclasses it to the mixed class
  • for the second IParrot, the object factory generates the base call proxy with no life of its own, delegating everything to the mixed class