...
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 toParrot_BaseCallProxy_SOM3GUID
(labeled "Parrot_BaseCallProxy..." in the illustration) inBase
Parrot_BaseCallProxy_SOM3GUID
holds a reference to the mixed classParrot_Mixed_SOM3GUID
(labeled "Parrot_SOM3GUID")Parrot_BaseCallProxy_SOM3GUID
implementsIParrot
(note that, in this diagram,Parrot
orParrot_Mixed_SOM3GUID
do not}}Parrot_Mixed_SOM3GUID
has been endowed with aBase_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 theSay ()
method inParrot_BaseCallProxy_SOM3GUID
Parrot_BaseCallProxy_SOM3GUID
'sSay ()
method delegates toBase_Say ()
inParrot_Mixed_SOM3GUID
Parrot_Mixed_SOM3GUID
'sSay ()
delegates toParrot
'sSay ()
viabase.Say ()
(note the lowercase 'b' inbase.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 findsParrot
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