Re: CLOS Properties Question

From: Antonio Menezes Leitao (Antonio.Leitao_at_evaluator.pt)
Date: 05/16/04


Date: Sun, 16 May 2004 00:31:52 +0100

On Sat, 15 May 2004 21:12:57 +0200, Pascal Costanza wrote:

> [...]
> Java and C# have adopted a somewhat strange mixture of those imperative
> and declarative styles. In interfaces, you can declare methods, but you
> don't actually create them. However, you are not allowed to declare
> fields there, although that would have been perfectly reasonable. A
> field declaration in an interface could just have led to the requirement
> that such a field should exist in any class that declares to implement
> such an interface. This mess was the result of the fact that interfaces
> in Java just evolved from pure abstract classes in the C++ sense. There
> is even an OOPSLA or ECOOP paper published before the advent of Java
> that just describes the idiomatic use of pure abstract classes as
> interfaces in C++, together with the claim that the only reasonable use
> of multiple inheritance is to inherit from one non-abstract and zero or
> more purely abstract superclasses. That's just what the Java designers
> adopted, without thinking deeply enough about the consequences. (And
> this is in fact one of the best indications that C# is just a bad copy
> of Java, because they also just adopted Java's design decisions, with
> only some superficial syntactic sugar added, but without going
> significantly deeper.)
>
> Back to the question what this all has to do with multiple inheritance:
> If interfaces in Java and C# allowed for field declaration, roughly as
> described above, then you would indeed have a first step for a
> reasonable design for proper multiple inheritance. But that would just
> be another instance of Greenspun's tenth rule. Specifically, I disagree
> that C# properties are good solution to a well-understood problem.

I suggest you take a look at Linj, the Lisp to Java translator. Linj
implements a poor's man approach to multiple inheritance based on the idea
of mixins: you inherit from one base class and any number of mixins.
Mixins are classes that inherit from other mixins and that can't be
instantiated but, other than that, they don't have limitations: you can
define slots and/or methods just like in normal classes. When these
mixins are translated into Java interfaces they loose the non-constant
slots and the methods become abstract (loosing their bodies). However,
classes that inherit from the mixin will get copies of the remaining slots
slots and of the methods.

It can lead to code bloat, of course, but it's much better than doing code
bloat by hand, humm, I mean, copy & paste :-)

Antonio Leitao.



Relevant Pages

  • Re: getting round multiple inheritance
    ... As java doesnt allow multiple inheritance, I can't use Observable as well as RMI. ... In Java you use interfaces as a sort of replacement for multiple inheritance. ...
    (comp.lang.java.programmer)
  • Re: Java "interface" vs. OO interface
    ... > IMHO the reason that the Java designers came up with the notion of ... > having to deal with multiple inheritance of implementation. ... I always though that the interfaces feature was added as an afterthought to ... Not that the idea of interfaces is entirely without merit, but Java ...
    (comp.object)
  • Re: Java "interface" vs. OO interface
    ... >> IMHO the reason that the Java designers came up with the notion of ... >> having to deal with multiple inheritance of implementation. ... > I always though that the interfaces feature was added as an afterthought to ... > Not that the idea of interfaces is entirely without merit, but Java ...
    (comp.object)
  • Re: Implementing inheritance in JAVA
    ... > interfaces to the specific instance variables of tyep Bimpl and Cimpl ... On Multiple Inheritance in Java ... and object composition. ...
    (comp.lang.java.programmer)
  • Re: dynamic type checking - a pauline conversion?
    ... to actually write the code in Java. ... Is the query handled ... One of the problems with Java typing is small differences in interfaces ... array iteration, List iteration, and database query result iteration all ...
    (comp.object)