Interface listFW.IListAlgo


public interface IListAlgo
extends Object
Represents an abstract algorithm to be executed by a host IList. Plays the role of a "visitor" in the design pattern language.

In non OO programming paradigms, an algorithm on lists is expressed as a function or procedure that takes in a list as parameter. In our OO formulation, an alogrithm on lists is an interface that has two methods, each takes in a list as a parameter:

When we want to perform an alogrithm (IListAlgo) on a list (IList), we asks the IList to 'execute' the algorithm with a given input. An MTList knows instrinsically that is empty and calls the emptyCase method of the IListAlgo. Analogously, a non-empty list (INEList) will correctly call the nonEmptyCase method of the IListAlgo.

One need not (and should not) check for the type of a list before applying an algorithm to it. THERE IS NO "if"!

Author:
Dung X. Nguyen, Stephen B. Wong

Method Index

 o emptyCase (IMTList, Object)
Operates on MTList, the empty list
 o nonEmptyCase (INEList, Object)
Operates on NEList, a non-empty list

Methods

 o emptyCase
public abstract Object emptyCase(IMTList host, Object inp)
Operates on MTList, the empty list. Since IEmptyList has only one method, execute(), there is not much the host list can do here. So the code for the empty case usually involves:

Parameters:
host - the IMTList that is executing this algorithm.
inp - generic input parameter that can be used for any purpose.
Returns:
result from calling this method. The type of the result is problem-specific and may be null.
 o nonEmptyCase
public abstract Object nonEmptyCase(INEList host, Object inp)
Operates on NEList, a non-empty list. The host list now has a first and a rest. So the code here usually involves what host.getFirst() and host.getRest() can do to accomplish the task at hand.

To summarize, the code for the non-empty case usually involves:

Parameters:
host - the INEList that is executing this algorithm
inp - generic input parameter that can be used for any purpose.
Returns:
result from calling this method. The type of the result is problem-specific and may be null.