Compare classes in Java to the drawers of a file cabinet to model object oriented programming through an easy to recognize analogy.

  • The drawers of a file cabinet represent classes, while manila folders in the drawer represent objects.
  • Bring manila folders to class to make the analogy concrete.
    • Write the name of the object on the folder’s tab.
    • Label the upper right corner with the class the object belongs to.
    • Place instance variables and methods inside the folder.
    • After a while, you can simply draw the objects as folders on the board because this will be a convention your students now recognize.
    • When drawing subclasses, draw them one above the other on a single file folder, with the most super class at the top.
      • Draw all components the subclass inherits from the superclass in the subclass’ section of the folder.
    • Then teach students the bottom-up rule: "given a method call, search for a matching method starting at the bottom of the object and search upward."
  • Below are examples of labeled manila folders drawings according to the analogy above:
    • In object a0 below, a0 is associated with the class C. its methods are C(int) and toString(), and name is an instance variable of type String that has not yet been assigned. Class association, instance variables, and methods for object a0
    • In object a1 below, a1 is associated with the classes Circle, Shape, and Object. Object is the most super, the "super-est," class. Class association, instance variables, and methods for object a1

More about this tip

External Source
"A principled approach to teaching OO first" by David Gries under "3. The OO Model of Execution."