In my last blog entry on this topic I made the following bogus statement:
"We knew the thing was a Stack, meaning, it implemented the abstraction of a Stack abstract data type, by reading the implementation, and slowly figuring out, "hey, this looks like a stack", and these operations look like operations we normally do on Stacks." to explain how I translated some foreign code into English.
As a reminder, here again is the foreign code:
public interface Pila {
void agregar (Object o);
Object extraer();
Object verTope();
boolean estaVacia();
void Vaciar();
}
And here's the Stack "interpretation"
public interface Stack {
void push (Object o);
Object pop ();
Object getTop();
boolean isEmpty();
void empty();
}
The statement is bogus, and someone should have taken me to task for making it, (anyone reading these postings?) because you should not have to figure out the semantics of an interface from its implementation. That's pretty circular reasoning. How do you know the implementation is faithful to the "intent" of the interface, if your understanding of the interface comes from your understanding of the implementation?
I could just as easily have translated the Spanish code into:
public interface Pile {
void add (Object o);
Object extract();
Object seeEnd();
boolean isEmpty();
void empty();
}
How would I know what's required of the implementation?
What if I had:
public interface Queue {
void add (Object o);
Object extract();
Object seeEnd();
boolean isEmpty();
void empty();
}
How do you tell a Stack, from a Queue from a Foo? The answer, lamentably, points out to a glaring deficiency in the Java interface mechanism: the interface cannot possibly tell you the semantics of the defined operations. In other words, a Java interface is inherently unreadable. Claiming that you've read and understood a Java interface would be a vacuous statement. You have no clue what the intended semantics are.
How would you get a clue about the intended semantics?
That's the topic of the next look. Design By Contract.
Recent Comments