Created
February 28, 2013 08:25
-
-
Save einarwh/5055162 to your computer and use it in GitHub Desktop.
Canine polymorphism example for blog post.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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