Subj : Re: Change Patterns (was: Polymorphism sucks) To : comp.programming,comp.object From : rem642b Date : Wed Aug 10 2005 03:44 pm > From: Programmer Dude > I've been at this 30 years and have no favorite language, OS, editor > or programming technique. Every viable tool has a welcome place in > my toolbox. Aren't you carrying that to an extreme? Surely there are some that are more commonly useful than others, such that you often use them and only occasionally use some of the less-commonly-useful ones? There must be some semi-favorites among the hodgepodge of them all? Do you consider relational databases, C, Lisp, XML and Java no more useful on average than awk, sed, tvedit, teco and SPS? > I think some of the hierarchies in the Java library are pretty > well-designed, for example. One really losing thing about the Java package/class hierarchy is that only compiletime interfaces are supported, so the only interfaces that can possibly exist are the ones that pre-dated the compilation of the particular class that implements the interface. There's no way to set up after-the-fact interfaces, like if you notice ten existing classes already support three methods you want to use polymorphically, there's no way to declare that you have an object of type MyNewInterface (defined as those three methods) and to declare that each of the ten pre-existing classes implements that interface. Using the reflections API I worked out a hack to bypass this restriction, to have true runtime after-the-fact interfaces, with the pain that you can't call the three methods directly, you have to use the reflection API every time you call one of the three methods. Note that you can sub-class each of those ten pre-existing classes, whereby your sub-class iimplements your new interface, and you can have the constructors for your ten sub-classes simply call the constructor for the parent class, so if you always create your own instances, and you don't mind creating sub-class instances instead of original-class instances, that would work. But if you get objects from other places, such as a HttpServlet container, you already have the object of the parent class and Java provides no way to coerce it to the sub-class or otherwise allow that actual object to implement your new interface. .