Concepts of Programming Languages

(Sean Pound) #1

570 Chapter 12 Support for Object-Oriented Programming


defined in child library packages, in which case entities of the parent type can
be eliminated in the derived type. Outside child library packages, all subclasses
are subtypes.
C#, which is based on C++ and Java, supports object-oriented program-
ming. Objects can be instantiated from either classes or structs. The struct
objects are stack dynamic and do not support inheritance. Methods in a derived
class can call the hidden methods of the parent class by including base on the
method name. Methods that can be overridden must be marked virtual, and
the overriding methods must be marked with override. All classes (and all
primitives) are derived from Object.
Ruby is an object-oriented scripting language in which all data are objects.
As with Smalltalk, all objects are heap allocated and all variables are typeless
references to objects. All constructors are named initialize. All instance data
are private, but getter and setter methods can be easily included. The collection
of all instance variables for which access methods have been provided forms the
public interface to the class. Such instance data are called attributes. Ruby classes
are dynamic in the sense that they are executable and can be changed at any
time. Ruby supports only single inheritance, and subclasses are not necessarily
subtypes.
The instance variables of a class are stored in a CIR, the structure of which
is static. Subclasses have their own CIRs, as well as the CIR of their parent
class. Dynamic binding is supported with a virtual method table, which stores
pointers to specific methods. Multiple inheritance greatly complicates the
implementation of CIRs and virtual method tables.

REVIEW QUESTIONS



  1. Describe the three characteristic features of object-oriented languages.

  2. What is the difference between a class variable and an instance variable?

  3. What is multiple inheritance?

  4. What is a polymorphic variable?

  5. What is an overriding method?

  6. Describe a situation where dynamic binding is a great advantage over its
    absence.

  7. What is a virtual method?

  8. What is an abstract method? What is an abstract class?

  9. Describe briefly the eight design issues used in this chapter for object-
    oriented languages.

  10. What is a nesting class?

  11. What is the message protocol of an object?

  12. From where are Smalltalk objects allocated?

Free download pdf