In smalltalk each class contains a pointer to the class


In Smalltalk, each class contains a pointer to the class template. This template stores the names of all the instance variables that belong to objects created by the class.

(a) The names of the methods are stored next to the method pointers. Why are the names of instance variables stored in the class, instead of in the objects (next to the values for the instance variables)?

(b) Each class's method dictionary stores the names of only the methods explicitly written for that class; inherited methods are found by searching up the super- class pointers at run time. What optimization could be done if each subclass contained all of the methods of its superclasses in its method dictionary? What are some of the advantages and disadvantages of this optimization?

1476_Smalltalk run-time structures for Point and PolarPoint.png

(c) The class template stores the names of all the instance variables, even those inherited from parent classes. These are used to compile the methods of the class. Speci?cally, when a subclass is added to a Smalltalk system, the methods of the new class are compiled so that, when an instance variable is accessed, the method can access this directly without searching through the method dictio- nary and without searching through superclasses. Can you see some advantages and disadvantages of this implementation decision compared with looking up the relative position of an instance variable in the appropriate class template each time the variable is accessed? Keep in mind that in Smalltalk, a set of classes could remain running for days, while new classes are added incremen- tally and, conceivably, existing classes could be rewritten and recompiled.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: In smalltalk each class contains a pointer to the class
Reference No:- TGS01269955

Expected delivery within 24 Hours