Object Oriented Programming and Data Abstraction

Object Diagrams


Java programmers need to understand the difference between primitive types and object types. For this reason, it is helpful to draw object diagrams.

The primitive types are int, boolean, float, double, char, ... (they always begin with a lower case letter). The object types are classes (and interfaces) which have been defined by java programmers. Some common object types are String, List, ArrayList, HashSet, ... (they begin with upper case letters).

When drawing an object diagram for a variable (whether it is a local variable, a parameter, or a field):

  1. Draw a box, and label the box with the variable's name.
  2. Put the value of the variable inside the box:
  3. If the variable has not been assigned a value, use the following:
  4. If the variable is an object type which has been assigned a value, that value will be a reference to an object. Show this with an arrow to a large box in which the object's data is shown.
  5. In the object's data box, show the name of each field (i.e. instance variable), and its value in a box, using these instructions.
  6. For objects which are collections, use these guidelines:
  7. Continue to apply these instructions until all relevant variables have values.
  8. To simplify object diagrams, it is ok to treat Strings and wrapper classes (i.e. Integer, Boolean, Character, ...) as primitives.

An example of an object diagram.