// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; namespace E { public abstract class Bar { public abstract void RealM(); public void M() { RealM(); } } public class Bar1 : Bar { public override void RealM() { Console.WriteLine("Bar1 here"); } } public class Bar2 : Bar { public override void RealM() { Console.WriteLine("Bar2 here"); } } public class Foo { private Bar bar; public Foo(Bar bar) { this.bar = bar; } public void MM() { bar.M(); } } public class Program { public static void Main(string[] args) { Foo foo1 = new Foo(new Bar1()); foo1.MM(); Foo foo2 = new Foo(new Bar2()); foo2.MM(); } } }