Concepts of Programming Languages

(Sean Pound) #1
logic expressions and conventional control statements. One of the Smalltalk
control constructs is illustrated in the example in the next subsection.

2.15.3 Evaluation


Smalltalk has done a great deal to promote two separate aspects of comput-
ing: graphical user interfaces and object-oriented programming. The window-
ing systems that are now the dominant method of user interfaces to software
systems grew out of Smalltalk. Today, the most significant software design
methodologies and programming languages are object oriented. Although the
origin of some of the ideas of object-oriented languages came from SIMULA
67, they reached maturation in Smalltalk. It is clear that Smalltalk’s impact on
the computing world is extensive and will be long-lived.
The following is an example of a Smalltalk class definition:

"Smalltalk Example Program"
"The following is a class definition, instantiations
of which can draw equilateral polygons of any number of
sides"
class name Polygon
superclass Object
instance variable names ourPen
numSides
sideLength
"Class methods"
"Create an instance"
new
^ super new getPen

"Get a pen for drawing polygons"
getPen
ourPen <- Pen new defaultNib: 2

"Instance methods"
"Draw a polygon"
draw
numSides timesRepeat: [ourPen go: sideLength;
turn: 360 // numSides]

"Set length of sides"
length: len
sideLength <- len

"Set number of sides"
sides: num
numSides <- num

2.15 Object-Oriented Programming: Smalltalk 87
Free download pdf