Skip to content

Instantly share code, notes, and snippets.

@einarwh
Created February 28, 2013 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save einarwh/5055162 to your computer and use it in GitHub Desktop.
Save einarwh/5055162 to your computer and use it in GitHub Desktop.
Canine polymorphism example for blog post.
public enum Food { Biscuit, Meatballs, You }
public interface ICanine
{
string Bark { get; }
bool Eats(Food f);
}
public class Wolf : ICanine
{
public virtual string Bark { get { return "Aooo!"; } }
public bool Eats(Food f) { return f != Food.Biscuit; }
}
public class Dog : ICanine
{
public virtual string Bark { get { return "Woof!"; } }
public virtual bool Eats(Food f) { return f != Food.You; }
}
public class Chihuahua : Dog
{
public override string Bark { get { return "Arff!"; } }
public override bool Eats(Food f) { return f == Food.Biscuit; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment