Object: Identity vs. Environment
joel at ikestrel.com
Thu May 29 05:55:55 UTC 2003
> > However, that same distinction can be made for any class: 1) is an
> > instance of MyClass, 2) is not an instance of MyClass.
> Firstly, #isFoo should not be about any particular class. It should be
> about the behavioral protocol supported by a receiver of #isFoo. To care
> about the class of an object violates encapsulation.
I was simply saying that if you're talking about distinctions than why
doesn't the same logic apply to other distinctions?
> If the question is whether or not adding an #isFoo method to Object is
> a priori a violation of good design principles--specifically, the
> that classes should only have methods whose domain naturally includes or
> involves instances of the class--then the answer is an unequivocal no.
> I would prefer to use #conformsToProtocol: as the general mechanism for
> whether or not any object conforms to any particular protocol, and reserve
> for the most commonly used cases (because of the speed advantage.)
Why not use #conformsToProtocol always (which is #4 that I suggested)? Why
is there a speed advantage with #isFoo? Conceptually (to me) both are
dictionary lookups and that's it. I would think either could be equally as
fast. And considering the protocol dictionary would be smaller than the
method one, protocol might could be faster.
More information about the Squeak-dev