[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Java interface natural history was RE: "static" declaration



While I agree that interfaces are important in Java, i miss mixins and 
multiple inheritance as in Common Lisp, for example.  In Java you need to 
implement the interface over and over.

Your message made me curious about how interfaces are actually used in Java.
Here's what i found by scanning JDK1.4's rt.jar:
8128 classes
  965 interfaces
5559 classes that implement an interface
  456 Throwables

Other jars could have a higher interface ratio, and certainly user code 
might have more concrete classes that implement those interfaces.

Here's a histogram of number of interfaces a class implements:
("#implements" "#classes")
(38 1)
(36 1)
(34 1)
(32 2)
(24 1)
(17 7)
(16 15)
(15 5)
(14 8)
(13 4)
(12 23)
(11 53)
(10 81)
(9 27)
(8 77)
(7 89)
(6 133)
(5 445)
(4 242)
(3 480)
(2 1078)
(1 2786)
(0 2569)

Here's a histogram of the depth of a class in the class hierarchy:
("depth" "#classes")
(9 2)
(8 26)
(7 144)
(6 406)
(5 618)
(4 1040)
(3 1726)
(2 3200)
(1 966)

At 02:57 AM 8/7/2002, Anton van Straaten wrote:
> > Personally, I consider Java heavyweight because it has a restrictive
> > typing system that is heavily coupled with inheriting behaviour.
>
>That "heavily coupled with inheriting behaviour" bit is completely optional
>in Java, although many people don't fully realize it.  The way one *should*
>design and code in Java is to use explicitly declared interfaces to decouple
>interface from implementation.  One then gains types (interfaces) that are
>100% decoupled from implementation inheritance.  (In real Java systems, the
>number is a little lower than 100%, but often not by much.)
>
>This can have enormous benefits to system design, refactoring capability,
>and even for things like build time (implementation changes don't trigger
>recompiles of clients).
>
>The design of a properly interface-oriented set of Java classes can be a
>significant improvement over similar classes in a dynamically-typed OO
>language.  Support for multiple explicit interfaces on a class allows for
>decoupling and factoring of designs in ways that make a great deal of sense,
>but often aren't practical to maintain in dynamically typed languages.
>
>Anton