View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Question 3(OO concepts)

(a)The methods grow:, move: and turn: defined in Box all have the same structure. What is the outline that they have in common and what is its purpose?

The outline is:

The purpose is to erase the old version before changing on of the instance variables (since undraw depends on the old version of the variable) and then display the new state of the box after the instance variable has been changed

3 points for the outline
2 points for the purpose
Note from TA: I talked to Rich about what made a valid purpose.
He and I both agreed that if the student included something about
reuse, he or she would receive a point for that.

(b) If Box defines class message new as ^super new initialize (which it does), executing Box new (as in joe := Box new) defines a new Box—not a new Object, or a new Class, or a new Behavior.

The new object created is an instance of self. SInce the class Box was the receiver of the new message that started the creation process, it determines the type of the object created.

2 points for explicitly mentioning that the new object is "an instance of self."
3 points for the general concept that the class of the new object is determined by the recipient of the new message .

(c) Let’s say that we had a subclass of Box named ColoredBox. Let’s say that ColoredBox defines class message new as ^super new initialize, just as Box does. Let’s imagine that ColoredBox’s initialize method contains the statement Transcript show: ‘Hello, World!’; cr. How many times will “Hello, World!” be printed on the Transcript? Why?

Twice, since the initialize message will be sent to the new instance twice, once by new as defined in Box and once by the new method defined in ColoredBox.

2 points for "twice"
3 points for an explanation that indicates they know that the initialize message in the new method of Box result in execution of the initialize method defined in ColoredBox.

Link to this Page