Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Objects "know" what they are.   An empty list knows that it is an empty list and does not need to be told such and likewise, non-empty (cons) lists know that they are non-empty and thus have a first and rest. 
    • Objects have behaviors, i.e. objects contain functions ("methods").    That is, the functions to process an object, e.g. a list, are built into the list.  (at least for now).
    • Never ask an object what it is.   The object already knows.   Let the object do what it already knows how to do.   Delegate to the object, don't query its type!
    •  
  • Objects are part of an inheritance hierarchy, which in part, determines their type. 
    • Empty lists and cons (non-empty) lists are lists and thus are sub-types of ("extend") the abstract superclass, IntList, which represents *all* lists, i.e. the "union" of all empty and non-empty lists.

More List Exercises

Recall our object model (common known in the Scheme world as "data definition") for lists of int.

...