Question 0-4

How does a Smalltalk system store class methods internally?

Solution

When you define a class in Smalltalk, the system creates two objects: a Class object A representing the class, and a Metaclass object B. Smalltalk remembers B as being the class of A. Any class methods are stored in the method dictionary held by B (and any instance methods are stored in the method dictionary held by A). In this way, all methods are treated identically, regardless of being an instance method or a class method: The method goes to the class of the receiving object and looks the method up in the method dictionary found there.

Back to Exam Review 0