Re: Java "interface" vs. OO interface
From: Dave Harris (brangdon_at_cix.co.uk)
Date: 11/22/03
- Next message: Ron Jeffries: "Re: Dark Forces Shall Not Prevail [off/on topic]"
- Previous message: Sebastian Czort: "Re: XP Question about Metaphor"
- In reply to: Thomas G. Marshall: "Re: Java "interface" vs. OO interface"
- Next in thread: Uncle Bob (Robert C. Martin): "Re: Java "interface" vs. OO interface"
- Reply: Uncle Bob (Robert C. Martin): "Re: Java "interface" vs. OO interface"
- Reply: Isaac Gouy: "Re: Java "interface" vs. OO interface"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 22 Nov 2003 13:29 +0000 (GMT Standard Time)
tgm2tothe10thpower@hotmail.replaceTextWithNumber.com (Thomas G. Marshall)
wrote (abridged):
> > I think Java uses interfaces instead of classes because the designers
> > couldn't figure out a good implementation of MI of classes. The
> > ideology was a post-hoc justification.
>
> No. Interfaces allow entire subsystems to be describable in java
> without a single class being supplied, abstract or otherwise.
This is achieved by changing the terminology so that some abstract classes
are not called classes any more. It's just terminology; it's not letting
you do anything new.
> There is elegance and just plain old good sense in having a
> language construct actually personify the contract without
> implementation.
Except Java doesn't do that, because it doesn't support pre-conditions or
post-conditions. One of the uses of non-abstract interface classes in C++
is to provide wrapper functions which do such checks. Along the lines of:
class MyInterface {
public:
int get_data( int index ) {
assert( 0 <= index && index <= 100 );
int result = get_data_impl( index );
assert( 0 <= result && result <= 10000 );
return result;
}
protected:
virtual int get_data_impl( int index ) = 0;
};
Notice that get_data() is not virtual, so that the checks cannot be
circumvented. This also shows it can make sense for interfaces to have
non-public methods.
Sometimes interfaces want to have code. Another example is where a default
implementation can be written in terms of the pure virtual methods. In
this case the implementation /is/ virtual, so it can overridden where
necessary, so it doesn't represent a commitment to representation.
One use of such virtual methods with default implementations is evolving
an interface forward without breaking old subclasses. You can add new
methods, and old subclasses don't need to change to implement them. And
this use shows that giving the pure abstract base class a special keyword
is a mistake. It would /force/ the subclasses to change, from "implements"
to "inherits".
-- Dave Harris, Nottingham, UK
- Next message: Ron Jeffries: "Re: Dark Forces Shall Not Prevail [off/on topic]"
- Previous message: Sebastian Czort: "Re: XP Question about Metaphor"
- In reply to: Thomas G. Marshall: "Re: Java "interface" vs. OO interface"
- Next in thread: Uncle Bob (Robert C. Martin): "Re: Java "interface" vs. OO interface"
- Reply: Uncle Bob (Robert C. Martin): "Re: Java "interface" vs. OO interface"
- Reply: Isaac Gouy: "Re: Java "interface" vs. OO interface"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|