Tuesday Mar 10, 2009

Tomacco

I had another programmer come over and ask me a question that centered around inheritance. Specifically, trying to understand how/why subclass Bletch could see property 'bar' from superclass Foo:

public class Foo {
   int bar;
   ...
}

public class Bletch extends Foo {
   public int count() {
      return bar++;
   }
   ...
}
I reminded him how inheritance works (he is new to OO), but we also discussed composition. As an example I worked up to the Tomacco plant: it extends Tomato, but contains an instance of Tobacco so that it can respond to hasNicotine():
public class Tomacco extends Tomato {
   Tobacco t = new Tobacco();

   public boolean hasNicotine() {
      return t.hasNicotine();
   }
   ...
}
                    

Monday Apr 30, 2007

Re: Blind pilot flies from London to Sydney

But he was trying to get to Quebec! Okay, not really, but that was my first response to the headline.

Wednesday Apr 11, 2007

back in the saddle?

From time-to-time I remind myself that I really should get brainopolis.com and Vanity Foul back on the air. In our "new" home there are some infrastructure issues that I've just been loathe to tackle. Not that anybody is paying attention to my second blog here (thanks Dave), but let me know if you'd like to hear from me more often.

Re: 5 years of blogging

I'm going to make this a chain; from RE: 5th anniversary of Blogging Roller

From the Blogging Roller himself:

Today is the fifth anniversary of this blog, which I started on April 11, 2002 to promote the Roller blog software that I had just finished writing.
...
Now, five years later, Roller has graduated from the Apache Incubator to become Apache Roller, blog-tech is my full-time job at Sun and I'm still Blogging Roller. Thanks to Roller users and contributors everywhere for helping to make this possible.

Congrats Dave - 5 years is 20 years in Internet Time isn't it?!

Add my congrats. I've taken a nearly two year mostly-hiatus from blogging, but I'm still around. My 5 year anniversary comes up in Aug.

Friday Jul 07, 2006

Why television is bad for democracy

Okay, I overstated it a bit with that title, but this quote really struck me.

... he says that image media bypass reason and go straight to the emotions. The image media are a metaphor for not thinking logically. Images disable thinking, so unless people read and use their reason democracy is disabled as well. [Is Media Performance Democracy’s Critical Issue?]

Monday Jun 12, 2006

Beautiful Girl

Since I'm too lazy to hunt up his email address I just had to post a note saying Tim Bray has got a beautiful girl!

Thursday Apr 20, 2006

Oil Companies Exploiting Gas Crisis?

Who could believe it? Of course, our President says he'll be on the lookout for price gouging, so I feel much better about it.

Wednesday Apr 19, 2006

I'm learning to hate constructors

Of course, that's partially to do with the way "things are done" here. We've got a base class (we'll call A) that takes the form of Constructor(int id) where the constructor then loads values from the database after doing a lookup on id, among other things.

I've been working on a set of classes that need to work on a second database (something the original set of data objects didn't need to do), so I created an abstract class (we'll call B) which subclasses A and does some common work (common to this second set). And I've got subclass C of B.

Now, B is abstract, so it doesn't need constructors, but C has to be compatible with A (for use in a Factory) so it does have to have C(int id). But to avoid compilation errors in C(int id) { super(id); } I do have to specify B(id) { super(id) }.

So, my abstract class does have to have a Constructor. Or I can copy-paste the work A(id) does into C(id).

Have I mentioned that there is no way to enforce this Constructor(int id) contract, except by discovering that the Factory cannot instantiate your C? I could fix the Factory such that it doesn't build an object by calling a constructor, add a FactoryInterface with an initialize(id) method, and have the Factory use that instead. Now c.initialize() can override a.initialize() with no need for b.intialize(); and I only have to get this approved by the rest of the development staff. And roll this change into the 20+ classes that inherit from A.