您在這裡

Abstract List Behaviors

6 六月, 2016 - 15:15
Available under Creative Commons-ShareAlike 4.0 International License. Download for free at http://cnx.org/contents/402b20ad-c01f-45f1-9743-05eadb1f710e@37.6

The concrete empty list and non-empty list implemented as MTList and NEList are now expressed as interfaces as follow.

package listFW;/** * Represents the abstract behavior of the immutable list structure. * A list intrinsically "knows" how to execute an algorithm on itself. */ interface IList { Object execute(IListAlgo algo, Object... inp); }
package listFW;
 
/**
 * Represents the immutable empty list.
 * The empty list has no well-defined structural behavior:
 * it has no first and no rest.
 */
interface IMTList extends IList {
}
 
package listFW;
 
/**
 * Represents the immutable non-empty list.
 * An immutable non-empty list has a data object called first, and an
 * isomorphic subcomponent called rest.  Its structural behavior
 * provides access to its internal data (first) and substructure (rest).
 */
interface INEList extends IList {
    /**
     * "Gettor" method for the list's first.
     * @return this INElist's first element.
     */
    Object getFirst();
 
    /**
     * "Gettor" method for the list's rest.
     * @return this INElist's rest.
     */
    IList getRest();
}