December 4, 2022

Variable-Reference Diagrams


Evaluating the following expression series in the Workspace will create an instance of Painting.

painting1 := Painting new.
painting1 title: 'Iron painting #20';
yearCreated: '1995';
height: 244;
width: 213;
media: 'Polyester resin, fillers, oil and gel on fibreglass;
price: 5000.0


Iron Painting #20 - 1995

The object painting1 models the painting depicited in this "thumbnail". Click on it to open a larger image.

Mention should be made of the initialize method:

   "Initialize the receiver as for the superclass then
   set framed to false. Answer the receiver."
   super initialize
   self framed: false

meaning that a new instance of Painting is initialised with its framed instance variable referencing false, a Boolean object, the only instance of the False class. The reasoning behind this is based on a design decision; framed could have been set to true, the only instance of the class True. Booleans will be revisited later.

Here is a variable-reference diagram, which illustrates painting1.

variable reference diagram

There are several things to note about this diagram.

  • Arrows pointing from a variable to an object are broken. Why so? The answer is that a variable, an identifier, references an object. The Smalltalk system 'knows' about objects because it stores these references. An object does not 'know' a variable. The broken arrow points in one direction only, signifying a one-way line of communication.
  • painting1 is the variable that references the object denoted by the 'rountangle', consequently it sits outside the object. This reinforces the notion of variables existing in the Smalltalk environment. Try thinking of this environment as 'the space surrounding the object'. Smalltalk 'knows' which variable references which object. This is implemented by means of assignment:
    painting1 := Painting new.
  • The object's attributes are listed inside the object with arrows pointing towards other objects. These objects are the values of the instance variables. This reinforces the notion of internally stored references to data. The object's attributes include all of those inherited from the superclass Artwork.
  • The protocol lists some of the messages that the object 'understands'. It does not include the protocol inherited from Object. This is normal practice due to space restrictions within the 'rountangle'.

These diagrams are used to understand assignment. We can now look at a simple problem.

Next page » An assignment exercise

Previous page « Class methods
































































Up to top of page