JJB Blog

Question: How do you know when a language’s OO/class/inheritance design is horrible?

Answer: when you have to write THE SAME METHOD in every single extension class:

[php]
public static function tableHeader(){
return parent::tableHeaderMaker(self::ColumnSpecs());
}
[/php]

PHP does not allow a parent class access to an extension class’ static methods (or members).

Or maybe this isn’t so strange? Can Smalltalk, Objective-C, Java, Ruby, or Python do this? I’m very interested…. if you are reading this and know one of these languages, please chime in.

Another gripe: see how I am calling self::ColumnSpecs()? I originally wanted to make ColumnSpecs a static member, but static members can’t have instantiated Classes (or an array of instantiated classes, in my case) assigned to them. So I have to use a static method to generate this array with each call. It works okay in this case, but it’s ugly, and incurrs a performance hit.

[php]
public static function ColumnSpecs(){
return array(
new ColumnSpec(‘shirt’, ‘Shirt’),
new ColumnSpec(‘mailingaddress’, ‘Address’),
new ColumnSpec(‘billingaddress’, ‘Address’),
new ColumnSpec(‘price’));
}
[/php]


1 Comment

my friend zane says:

I know of no static/non-interpretted language that would allow a parent class to call a child’s static method like what I understand you’re saying. It’s unfortunate, but true. It is possible in both Ruby and Perl as these languages determine methods at runtime, and so when you call a method, you’re just sending a “named message” off to “something” and if it responds, it responds. For Ruby and Perl, classes (modules) are just ways to inherit some code, but they don’t really impose any structure on the language, and the languages are naturally pretty free.

Posted by site admin on 30 August 2005 @ 11pm

Leave a Comment