visibility" of class object in favour of a global context

Joel Shellman joel at ikestrel.com
Wed May 28 05:50:54 UTC 2003


> These queries are typically intended to be polymorphic so their real
meaning
> is "do you understand what I think a Foo should be understanding"? Note
that
> in the previous I am saying "what I think" a Foo needs to understand.

Except if you really mean "what I think", the I is the inquiring object and
so the inquiring object is the only one who knows "what it thinks". Thus the
#isFoo would have to be on the inquiring object or on something that the
inquiring object trusts to know "what it thinks".

> The #isFoo messages are more like "weak type queries" where you may have
many
> different objects responding "yeah, I'm kinda like a foo here". Examples
for
> these queries are #isLiteral (are you a kind of thing that a compiler
knows
> how to get literal forms from?)

But isn't that something that the Compiler would know better?

> #isCollection (can I send #do: #size and the
> general collection protocol to you?)

But isn't that something Collections would know more about?

> #isPlayerLike (are you and end-user
> scriptable object?) etc.

Same thing. If I create a new object, maybe it could be various things, but
it could be rather an advantage to not have to explicitly state all the
interfaces (a la Java) that I support. In other words, it sounds to me that
the #isFoo is still somewhat early binding, isn't it?

> > But that's absurd to put that sort of method on Object,
> > isn't it? Ie. in Java (yes, that's where I'm
> > coming from) you would use instanceof, which should be easy
> > in Smalltalk:
> >
> > (myObject class) == (Foo class)

> If it maps straightforwardly to classes, then yes. Except that the above
> test doesn't include subtypes so your query should be "myObject isKindOf:
> Foo" which is generally considered bad style because it's early binding
> something which is mostly meant as a role (interface) of some object.

In java, instanceof does map to interfaces, and yes, that does map to
interfaces. However, what's the difference in time to bind between:

Foo implements SomeInterface

and

(sorry for the wrong syntax, but I think you'll understand)

Foo>>#isSomeInterface
    ^true

They both bind at compile time.

-joel



More information about the Squeak-dev mailing list