Concepts of Programming Languages

(Sean Pound) #1

534 Chapter 12 Support for Object-Oriented Programming


associated initialization of the inherited parent class member implicit or must
the programmer explicitly deal with it.

12.4 Support for Object-Oriented Programming in Smalltalk


Many think of Smalltalk as the definitive object-oriented programming lan-
guage. It was the first language to include complete support for that paradigm.
Therefore, it is natural to begin a survey of language support for object-oriented
programming with Smalltalk.

12.4.1 General Characteristics


In Smalltalk, the concept of an object is truly universal. Virtually everything,
from items as simple as the integer constant 2 to a complex file-handling sys-
tem, is an object. As objects, they are treated uniformly. They all have local
memory, inherent processing ability, the capability to communicate with other
objects, and the possibility of inheriting methods and instance variables from
ancestors. Classes cannot be nested in Smalltalk.
All computation is through messages, even a simple arithmetic operation.
For example, the expression x + 7 is implemented as sending the + message to
x (to enact the + method), sending 7 as the parameter. This operation returns
a new numeric object with the result of the addition.
Replies to messages have the form of objects and are used to return
requested or computed information or only to confirm that the requested
service has been completed.
All Smalltalk objects are allocated from the heap and are referenced
through reference variables, which are implicitly dereferenced. There is no
explicit deallocation statement or operation. All deallocation is implicit, using
a garbage collection process for storage reclamation.
In Smalltalk, constructors must be explicitly called when an object is created.
A class can have multiple constructors, but each must have a unique name.
Unlike hybrid languages such as C++ and Ada 95, Smalltalk was designed
for just one software development paradigm—object oriented. Furthermore,
it adopts none of the appearance of the imperative languages. Its purity of pur-
pose is reflected in its simple elegance and uniformity of design.
There is an example Smalltalk program in Chapter 2.

12.4.2 Inheritance
A Smalltalk subclass inherits all of the instance variables, instance methods,
and class methods of its superclass. The subclass can also have its own instance
variables, which must have names that are distinct from the variable names in
its ancestor classes. Finally, the subclass can define new methods and redefine
methods that already exist in an ancestor class. When a subclass has a method
whose name and protocol are the same as an ancestor class, the subclass method
Free download pdf