Hi, Am 04.11.2008 um 16:06 schrieb Konrad Hinsen:
An example of where Clojure lacks OO features, in my opinion, is your lazy-map library. It provides an additional implementation for an existing interface, which is a typical OO approach, and a very useful one. But although all your code is written Clojure, it looks like a kludge in having to use a feature (genclass) intended for Java compatibility and forcing an unnatural file structure (one file for the methods, one for the code generation, and one for the end-user wrapper) on the implementation.
I disagree. Clojure brings everything needed: multimethods. One defines a set of multimethods (the interface) and different arguments may have different implementations.
Inheritance can also be replaced with delegation without problems. And in fact lazy-map does not inherit from any maptype. Instead it delegates to another instance without caring for whether it's a struct map, hash map or sorted map. With inheritance each of this types would have needed an own lazy-x-map class. This is again some style of functional OO programming. Suppose get, contains?, etc. were multimethods. I would not have neededgen-class. I just would register my own implementations for the lazy- map.
But the problem is: Clojure's map interface is not implemented with multimethods. They have a Java side. If I want to provide a drop-in replacement I have to also serve that side. Hence I need gen-class. Or Java itself for that matter in case gen-class is too kludgy. I don't think that Clojure is that bad for object-oriented programming. It just looks a bit different than usual. Sincerely Meikel
smime.p7s
Description: S/MIME cryptographic signature