Tutorial 3: Visitor Pattern


Introduction

This tutorial consists of exercises on the visitor pattern discussed in class.  It also helps prepare for homework 02.  First, copy all the java source code for AListFW and its visitor from the link http://www.owlnet.rice.edu/~comp212/00-fall/tutorials/03/.   This link contains the packages scheme2 and scheme2.visitor.  Use the provided java classes as the starting point.


Exercises:

  1. Write a visitor called Length to compute the length of AListFW using direct recursion and without using helpers.  This visitor corresponds to the method length() of AList.
  2. Write a visitor called GetMin to compute the minimum of AListFW, assuming AListFW contains Integer objects.  GetMin should use a helper visitor called HelpGetMin to compute the minimum.  This corresponds to the getMin() method of AList as shown in http://www.owlnet.rice.edu/~comp212/00-fall/handouts/week03/.
  3. Write a visitor called Sum to compute the sum of AListFW, assuming AListFW contains Integer objects.  Write one version using direct recursion, and one version, called GetSum, using a helper visitor called HelpGetSum.
D. X. Nguyen, Sept. 17, 2000.
dxnguyen@cs.rice.edu