[plt-scheme] Stack Object

From: John Clements (clements at brinckerhoff.org)
Date: Tue Oct 15 21:31:32 EDT 2002

On Tuesday, October 15, 2002, at 09:36 PM, Paulo Jorge O. C. Matos 

>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>> What's the utility of an interface?
>> To support `is-a?' and `implements?' tests that are not necessarily
>> tied to implementation inheritance. They're intended to serve the same
>> role as Java interfaces, but in dynamic, first-class form.
> Hi,
> I'm not really aware with Java, but let me ask this: Why is print-name
> not in the interface of the stack example?
>> In particular, being an instance of stack<%> doesn't prevent an object
>> from being used more specifically as a named-stack%, just as the #t
>> result of `(integer? 4)' doesn't prevent 4 from being used more
>> specifically as an integer.
> I'm sorry, I really didn't understand what this had to do with a method
> being an interface or not.

Matthew is explaining the relationship between interfaces and objects.
An interface consists of a set of names.  In this case, the stack<%> 
is intended to capture the notion of "stack"-ness; that is, to be 
called a "stack",
an object should implement this interface.

An interface helps me to build abstractions (and therefore to break down
my program); if one part of my program implements a stack, and another
part uses it, it helps me to reason about my program if I know that the 
will interact with the stack only through this narrowed interface.  It 
frees me
to reimplement the stack without fear that clients of the stack are 
other methods it might have, and correspondingly it simplifies reasoning
about (and hence modification of) the client program.  All of this goes
3x for programs written by more than one person.

john clements

Posted on the users mailing list.