« Arafat's effects on the Middle-Eastern peace process | Main | Creating shim libraries in Linux »

Static substitution (Fowler Style)

Martin Fowler has a neat little article on refactoring class statics using instance variables. Most languages can't support polymorphism for static methods. e.g.

class A{
public void doInitStuff() { /*do stuff necessary for static init of B objects*/};
} ...
}
class B extends A{
public void doInitStuff() { /*do other stuff necessary for static init of B objects*/};
} ...
}
...
A a = new B();
A.doInitStuff(); /* but I'd quite like to polymorphically call B.doStuff(); Actually, could be trouble! */

Martin's solution is very elegant.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on November 12, 2004 4:18 PM.

The previous post in this blog was Arafat's effects on the Middle-Eastern peace process.

The next post in this blog is Creating shim libraries in Linux.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33