Re: Template method pattern in Java ???

From: Avner Ben (avner_at_skilldesign.com)
Date: 02/23/04

  • Next message: CABA: "Re: log4j : time in the file name"
    Date: Mon, 23 Feb 2004 10:04:07 +0100
    
    

    Steven Wurster wrote:

    > [snip]
    > From the client perspective, all classes are pure interfaces. The
    > only caveats being that contracts may refer to other routines and it
    > is possible to figure out how some routines are coded just from the
    > contract; and the fact that abstract classes cannot be instantiated.
    > But, in general, the client does not and should not care whether or
    > not a class has implementations for any of its routines. Just code to
    > the interface.
    >
    > From the descendant programmer perspective, this is a different issue.
    > It matters which routines are abstract because those will have to be
    > implemented should the programmer wish that specific descendant to be
    > instantiated. It is an orthogonal issue. The catch here is with
    > inheritance and polymorphism:

    Perhaps we need two kinds of interface: usage interface and extension
    interface.

    >
    > Java, Eiffel, and I'm guessing C#, treat every routine as potentially
    > polymorphic. C++ of course does not, and you have to ask for dynamic
    > binding, and have the foresight that it will be needed.

    In C#, as in C++, a method is non-virtual by default. I am not happy
    with that decision.

    But Eiffel
    > also allows for the inheritance of non-purely abstract classes. What
    > this means is that the descendant programmer has freedom to add
    > polymorphism to any class, and at the same time inherit from any other
    > class. Level of abstraction is irrelevant. This is different in Java
    > and possibly C#, where polymorphism can be added to any class, but
    > inheritance from another class at the same time is limited to purely
    > abstract ones (interfaces in the Java world). This severely limits
    > the concept of inheritance. That is my entire argument here. Java is
    > flawed in this notion.

    In C++, you can inherit from any class, abstract or otherwise and to my
    best knowledge, in Java, too. Java distinguishes between extends (base
    class) and implements (interface). C# does not. In C++ and C# you can
    use objects polymorphically only through messages predefined to be virtual.

    > [snip]
    > I'm not sure what you mean by repeating of the conditions? You mean
    > he repeates the pre and postconditions? This is nothing new. Eiffel
    > does this for you, automatically no less. Eiffel also automatically
    > takes care of joining multiply inherited routines when one is abstract
    > and the other isn't. For the cases where multiply inherited routines
    > are both implemented, you have to select which one is used "up the
    > tree", if you will, while you have full choice over how to define the
    > new routine in the new class.
    >

    We speak about documentation here - there is no formal DBC support in
    C++. Although Stepanov never mentions either Eiffel or B. Meyer, they
    seem to be at least influenced from the same source.

            Avner.


  • Next message: CABA: "Re: log4j : time in the file name"

    Relevant Pages

    • Re: Beginner, Which language
      ... > That's much more true for implementation inheritance than interface ... > compared to the run time support Java requires. ... > - All base classes of the interface must also be declared with interface ...
      (comp.programming)
    • Re: Question on abstract classes versus interfaces
      ... inheritance is not at all ... "interface A extends B"). ... In a language with no form of inheritance or delegation, ... layered over Java -- one with a different approach to OO in general. ...
      (comp.lang.java.programmer)
    • Re: Question on abstract classes versus interfaces
      ... do you conside single inheritance of interface inheritance at all? ... And there is inheritance between Java interfaces, ... of my abstract data types, ...
      (comp.lang.java.programmer)
    • Re: CLOS Properties Question
      ... This leads to what they call shadowing (at least in Java) ... In interfaces, you can declare methods, but you ... > field declaration in an interface could just have led to the requirement ... > Back to the question what this all has to do with multiple inheritance: ...
      (comp.lang.lisp)
    • Re: Template method pattern in Java ???
      ... > only caveats being that contracts may refer to other routines and it ... Perhaps we need two kinds of interface: ... > also allows for the inheritance of non-purely abstract classes. ... This is different in Java ...
      (comp.object)