Rice University - Comp 212 - Intermediate Programming
Fall 2001
Lecture #13 - Mutable Linear Recursive Structure Framework
A mutable linear recursive structure (LRStruct) can be in the empty state or in a
non-empty state. If it is empty, it contains no object. Otherwise, it contains an object
called first, and a LRStruct
object called rest. When we insert a data object into an empty LRStruct, it changes it state to non-empty.
When we remove the last element from an non-empty LRStruct, it changes its state to empty. We model a LRStruct using the state pattern, and as in the case of the immutable
list, we also apply the visitor pattern to obtain a framework.

The above public constructor and methods expose
the structure of a LRStruct to the
client and constitute the pure structural behavior of a LRStruct. They form a minimal and complete set of methods for manipulating a LRStruct. Using them, one can create an empty LRStruct, store data in it, and remove/retrieve
data from it at will. Below is a series of object diagrams showing snapshots
of an instance of LRStruct at run-time.

dxnguyen@cs.rice.edu
Copyright 2000, Dung X. Nguyen - All rights reserved.