Re: But is it Object-Oriented?
Daniel Bonniot <[email protected]>
| Newsgroups | gmane.comp.lang.nice.general |
|---|---|
| Message-ID | <[email protected]> |
>'many practicing programmers used to single-dispatching object-oriented
>languages complain that multi-methods just don't feel object-oriented.'
>...
>the extant generic-function-based approach to multiple-dispatching
>object oriented languages tends to encourage a function-oriented
>programming style at the expense of a data-abstraction-oriented
>programming style.
>
There is not less data abstraction when you have multi-method than when
you are restricted to mono-methods. In both cases, outside of the
package defining a class, you can only use the operations that are
public. You can also define new operations based on the existing ones.
The difference is that with mono-methods you will need to resort to
static methods, while multi-methods are more powerful (you can use
dispatch) and are more elegant to use for clients (method calls look
like they always do).
Take the typical exemple of data abstraction: stacks. A stack is
something that supports the operations pop, push, and isEmpty. From the
outside, you only know this, nothing about how it might be implemented
internally.
In Java, you can write:
public class StackUtils {
public static void clear(Stack s) {
while (! s.isEmpty())
s.pop();
}
}
// Use: StackUtils.clear(myStack)
While in Nice you would write:
public void clear(Stack s) {
while (! s.isEmpty())
s.pop();
}
// Use: myStack.clear()
I don't see why the second would violate data-abstraction, if the first
one doesn't. The fact is, neither does: they both simply use the public
interface of stacks to define a new operation.
Daniel
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click