|
Home
>
3. concept
>
3.3 types and classes
>
3.3.2 classes and slots
>
3.3.2.1 Exploring the difference between the Dylan model and other OO models.
>
3.3.2.1.1 The object no longer encapsulates the message, that's done by the module.
|
Previous
Next
|
|
|
|
|
|
Seth LaForge
|
Coming from an Object Pascal/C++ background as I do, I am
used to objects having different namespaces for their methods, so
I could say
"myWindow.draw(...)"
or
"myCardDeck.draw(...)".
In these languages there's no real reason for the method names to
be different; as you say, it's pure coincidence that the method
names happen to be the same. I find this often happening with my
own code, which coexists with a huge class library.
It seems that in Dylan we'll have to be careful to avoid methods to
unrelated objects having the same name, and use the module
renaming facility whenever conflicts arise. This isn't a horrible
thing, but it does seem like something of a pain.
|
|
|
You're right about avoiding conceptually different methods having
the same name in a single module. But it's more and less than
that.
Dylan won't let one name have different types of bindings in a
single context. That is, a name cannot refer to a generic function
*and* some other kind of value. And because slots are provided
with generic functions, one cannot have different behaviors when
used as a slot vs. a regular-old generic function.
When taken in the light of other OO language models for slot
access, the syntactic tricks for `.' and `:=' are somewhat confusing
because of their interpretation in terms of generic functions.
|
|
|
In such a setting, all such slots can be thought of as functions of
one variable evaluating to a method. The dylan cliche to give such
a behavior is something like this:
define class <my-window> (<object>)
slot id, init-keyword: id:;
end class;
define method draw (window :: <my-window>)
curry (my-window-do-draw, window);
end method draw;
define constant my-window-do-draw =
method (window, thing)
print (window.id);
print (thing);
end method do-draw;
Obviously, printing is not how you draw something, but this
example will execute with Marlais as follows:
? define variable w =
make (<my-window>, id: "this-window");
? w.draw ("that string");
"this-window"
"that string"
?
I don't recommend that this cliche be put forth as anything other
than a motivation for exploring the difference between the Dylan
model and other OO models.
|
|
|
|
|
|