Blaising Grattles Blaise Gratton lobs blog blabber

Chihuahua Inheritance

So, in August of 2014, my roommate happened upon a chihuahua in the middle of nowhere on a Saturday night in the pouring rain. This creature was then gifted to me (quite literally “Here, have a dog!”).

Now, I’m not one for small dogs... especially chihuahuas. They’re often neurotic and way too yippy (also, chihuahuas, as I was soon to find out, are pretty much guaranteed to have horrible breath). So I entered this relationship with this dog a skeptic. I wasn’t even convinced she was a real dog at first, since she didn’t eat or drink anything for about 24 hours - not even bacon. We surmised she must accept AAA batteries somewhere instead of food.

As time wore on, however, it became very clear that this was not a typical small dog or even a typical chihuahua (other than the horrible breath). She (Tazza) barely makes a sound ever, except when she wants to come inside - and even then it is one short bark. She is affectionate and behaved, other than occasional humping of one particular red blanket. She likes running, eats normally, and when she really wants something, she stands on her hind legs and waves her front paws together like an Italian saying “Bello, bello, belloooooo...”.

So naturally, when doing the C# koans for Nashville Software School, I thought it would only be appropriate to make a special instance of the chihuahua class for Tazza. The C# koans begin teaching class inheritance via a base class of Dog, which looks like:

    1. public class Dog
    2. {
    3.     public string Name { get; set; }
    5.     public Dog(string name)
    6.     {
    7.         Name = name;
    8.     }
    10.    public virtual string Bark()
    11.    {
    12.        return "WOOF";
    13.    }

All well and good - dogs have a name and they bark. The subclass of Chihuahua is then inherited from the Dog base, overriding the string of “Bark” to return “yip” and adding the method Wag():

    1. public class Chihuahua : Dog
    2. {
    3.     public Chihuahua(string name) : base(name)
    4.     {
    5.     }
    7.     public override string Bark()
    8.     {
    9.         return "yip";
    10.    }
    12.    public string Wag()
    13.    {
    14.        return "Happy";
    15.    }

The Chihuahua subclass is even further extended to the subclass of ReallyYippyChihuahua (which is no more yippy than the original Chihuahua class...):

    1. public class ReallyYippyChihuahua : Chihuahua
    2. {
    3.     public ReallyYippyChihuahua(string name) : base(name) { }
    5.     public new string Wag()
    6.     {
    7.         return "WAG WAG WAG!!";
    8.     }
    9. }

Such are the subclasses of Dog related to chihuahuas in the C# koans. Tazza’s subclass would be something like WorldsChillestChihuahua, inheriting from the Chihuahua class:

    1.  public class WorldsChillestChihuahua : Chihuahua
    2.  {
    3.       public WorldsChillestChihuahua(string name) : base(name) 
    4.       {
    5.       }
    7.       public override string Bark()
    8.       {
    9.           return "yips *once*";
    10.       }
    12.      public string NeedsSomething()
    13.      {
    14.          return "*furiously waves paws in the air*";
    15.      }
    17.      public bool IsAwesome()
    18.      {
    19.          return true;
    20.      }
    21. }

So now, we can instantiate the class of WorldsChillestChihuahua:

WorldsChillestChihuahua tazza = new WorldsChillestChihuahua("Tazza");

tazza.IsAwesome() returns true because she is! I mean, just look at this dog.

photo of Tazza the chihuahua