This tutorial consists of exercises on the visitor pattern applied to the immutable list framework and the use of anonymous inner classes as helpers to the visitors. Most of the exercises are lifted from previous homeworks, lab exercises or examples of list algorithms that do not use inner classes as helpers.
In all of the exercises that follow, first write appropriate JUnit test cases for each of the visitors, and then write the code for the visitors so specified. The unit test cases are in a sense the specification of the problem to be solved. Writing the test code before writing the actual code to solve the problem helps you focus more clearly on the problem and identify the issues that need addressing before working on a solution. As such, you will gain a deeper understanding of the problem at hand. All the helper visitors are to be written as anonymous inner classes.
First, click here to download the code for the list framework.
IList
with
matching parentheses as in Scheme. For example, ToString for the list
containing 1, 2 ,3, should return (1 2 3),
and ToString for the empty list should
return ().
Exam 1 is scheduled for Wednesday, Feb. 15, 2006 from 7:30 PM to 10 PM. Next week's lab will focus on helping you prepare for the exam. If you are done with the above problems, you can take a look at the following exams and start working on them as a way to prepare for this semester's exam.