'instance creation' method inheritance

Tagged:  •  

help-smalltalk gets a question fairly frequently from users who don't know how to create Directory instances. (Incidentally, the answer is that you should use the instance creation methods inherited from File class.)

This question comes because of the mental model imposed on coders' conceptualizations of Object-Oriented Programming; namely, that "create new object" is a special operation. This is wrong; there is no need to represent this operation as any different from the ordinary user-extensible operations provided by the system, be they methods or procedures or what have you. In Smalltalk, creating new objects is done by sending messages to other objects, just as with every other operation outside variable assignment.

The first instinct of a GST developer is that this should be documented in Directory's class comment. This instinct is wrong. As a rule, we don't feel it is necessary to document every inherited method on instances that a class happens to support; as instance creation is also done with inheritable methods, why should we document them specially?

Doing this would be as absurd as documenting in every class comment that you can compare identity with #==, or documenting for every Collection subclass comment that you can iterate over contained values with #do:. Just as their relationships imply these capabilities, so Directory class's relationship with File class implies its instance creation capability.

I am interested in what newcomers would see as a way to understand the correct mental model of instance creation, without documenting every place where the inherited instance creation methods would be sufficient.

User login