Override Polymorphism versus me and a pot of coffee.
Override Polymorphism versus me and a pot of coffee., Posted in Actionscript 3, June 20th, 2009

JIRA SDK-16960
Java explanation of Late-Binding

The Issue
Subclassing has one purpose, to further specialize. If I want to extend my ‘FarmAnimal’ class and call it ‘Chicken’ that is specialization. If I extend ‘Real-Estate’ with ‘Condo’, that is specialization. So, what if I want to further restrict the acceptable properties of my sub-class? Override polymorphism allows us to redefine a inherited method from our super-class but doesn’t allow us to sub-specialize the method arguments(parameters) and return type. Why is this? If the specialized arguments and return type are fully type-safe against the requirements of the super-class then what is the problem?

The Example
Say my class ‘FarmAnimal’ has a method.
public makeSpawn():FarmAnimal {}
Now, I have a class ‘Chicken’ extends ‘FarmAnimal’. ‘Chicken’ has methods associated with it that do not exist in ‘FarmAnimal’. However, when I call chiken.makeSpawn() I still get a class instance typed FarmAnimal. Which is correct, it returns a Chicken object typed as FarmAnimal because override polymorphism says so. Now, every time I want to use methods special to Chicken. I have to retype the object as chicken.
chik:Chicken = chicken.makeSpawn() as Chicken;
This is ok. Now, what if makeSpawn has a argument.
public FarmAnimal makeSpawn(mate FarmAnimal) {}
Thats cool but a Chicken can’t mate with a Pig so we’ve got to do something about this. Override polymorphism says we can’t change the arguments. Wouldn’t it be awesome if we could just re-define makeSpawn as
public makeSpawn(mate:Chicken):Chicken {}
Well we can’t. What are our options? Interfaces have the same restrictions. We usually end up abandoning polymorphism completely in order to accomplish the task at hand or creating manual type checking on every override to prevent the wrong type of object being passed. All arguments aside, Chicken is a FarmAnimal so it is theoretically type-safe against the super’s version of makeSpawn. I don’t understand why the rules of polymorphism can’t be adapted to support this type of behavior.

Any ideas? Hit me up on Twitter.

Safari 4 Tabs
Safari 4 Tabs, Posted in General, June 16th, 2009

With Safari 4 final, we lost our beloved top-tabs. However, hope is not lost. All you have to do is replace Safari.app with the beta version (15MB) and you’ve got your tabs back. Sadly, I cannot host the file so you need to get it some other way.

Yumm, Vegan Brownies
Yumm, Vegan Brownies, Posted in Food, June 1st, 2009

This is an extension of this recipe.

Ingredients:

  • 2 cups unbleached all-purpose flour
  • 1 1/4 cup unbleached evaporated cane sugar
  • 3/4 cup brown sugar
  • 3/4 cup unsweetened cocoa powder
  • 1 teaspoon baking powder
  • 1 teaspoon salt
  • 1/2 cup water
  • 1/2 – 3/4 cup Coconut Milk
  • 1 cup vegetable oil
  • 1 teaspoon vanilla extract
  • 3-4 tablespoon extra creamy peanut butter
  • 1 teaspoon Omega 3 & 6 oil

350 degrees, 9×13 pan is about 30 minutes. 8×8 pan is 55 minutes. And yes, when you mix this it will clump into one massive mix blob instead of a smooth batter you get with off the shelf mixes. Bake until it passes the penetration test. ( no gunk sticks to whatever your poking the brownies with )

Note: I added a few pieces of baking bittersweet chocolate, being made with Milk Fat turns this recipe into “Vegetarian” so I left it out here.

« Older Entries