Class Data

The issue raised in the last slide is actually part of a large discussion having to do with class data. The question of class data occurs in many object-oriented languages, and not just those that treat classes as object.

Briefly stated, the issue is this. Class data are data fields that are shared by all instances of a class. These are declared, for example, as static data fields in C++ or Java, or as class variables in Smalltalk.

All instances of a class have the same behavior. Having said that, the question is then who should be responsible for initializing a class value? It would appear that either nobody would do it, or everybody will.

This is a tricky issue, and is solved using a variety of generally ad hoc methods in the various different languages.

[audio] [real] Text to accompany slide9, in Chapter 20 of An Introduction to Object-Oriented Programming