public class ExampleTypeOne : IMixinAlpha, IMixinBeta {
public ExampleTypeOne(int alphaInt, string alphaString) {
this.SetAlphaInt(alphaInt);
this.SetAlphaString(alphaString);
}
public virtual bool BetaFoobar() {
return this.GetBetaFloat() >= this.GetBetaInt() * 3;
}
}
public class ExampleTypeTwo : ExampleTypeOne {
public ExampleTypeTwo(int alphaInt, string alphaString) : base(alphaInt, alphaString) { }
public override bool BetaFoobar() {
return this.GetBetaFloat() >= this.GetBetaInt() * 4;
}
}
static void Main(string[] args) {
ComponentExtensions.PopulateVirtualTable();
ExampleTypeOne one = new ExampleTypeOne(2, "Cool");
one.SetBetaFloat(30f);
one.SetBetaInt(10);
Console.WriteLine(one.GetAlphaInt() + one.GetAlphaString()); // "2Cool"
Console.WriteLine(one.BetaFoobar()); // "True"
ExampleTypeTwo two = new ExampleTypeTwo(3, "Spooky");
two.SetBetaFloat(30f);
two.SetBetaInt(10);
Console.WriteLine(two.GetAlphaInt() + two.GetAlphaString()); // "3Spooky"
Console.WriteLine(two.BetaFoobar()); // "False"
Console.WriteLine((one as IMixinBeta).BetaFoobar()); // "True"
Console.WriteLine((two as IMixinBeta).BetaFoobar()); // "False"
Console.ReadKey();
}
Code snippet taken from "Simulating Multiple Inheritance In C#".