Inheritance

This week I read two more chapters of Sadi Mertz’s  book .  The concept of inheritance at its surface is straightforward- a mechanism that delegates the transmission of messages among classes.  You have a superclass that communicates with its subclasses but each one of these subclasses can only communicate with the superclass.

Think of a raw turkey meat as a  superclass. From this superclass you can create subclasses with suggestive and yummy names such as baked turkey, grilled turkey, fried turkey, and the like (As of the time of this writing, it is the post Thanksgiving weekend so naturally I am eating a good amount of left over turkey).

Think of subclasses as specializations of the superclass. The superclass is an abstraction, an idea.  Its sole purpose is to be subclassed.  Raw Turkey meat is a good example of a superclass because you cannot eat it in this state (only if you are crazy or an animal) i.e. you have to cook turkey meat to an edible form. So baked turkey and grilled turkey are specializations of raw turkey . In other words baked turkey inherently  turkey meat but modified not to be raw anymore.

It is good to keep that separation says Sadi in her book because most of the problems of inheritance comes from the failure to strictly distinguish the  abstract from the concrete– in this turkey case what is inedible(raw meat) from what is edible(baked turkey, fried turkey, etc).

I am still a neophyte when it comes to programming inheritance. I am sure I will become more proficient in designing it the more practice I have with it.  For now I will leave you with my first attempt below. Note how each subclass inherits from the Turkey superclass via the code  “<” .

This turkey  class talk made me hungry. Need. More. Food.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s