Module hw06

Class MTList

java.lang.Object
provided.listFW.MTList
All Implemented Interfaces:
IList

public class MTList extends Object implements IList
Represents the unique empty list using the singleton pattern. Provides concrete code for the execute method: simply calls the emptyCase method of the IListAlgo parameter, passing to this method itself as the host and the given input Object as the input.
Author:
D. X. Nguyen, S. B. Wong
  • Field Details

    • Singleton

      public static final MTList Singleton
      Singleton Pattern
  • Constructor Details

    • MTList

      private MTList()
      Private constructor for the Singleton
  • Method Details

    • execute

      public final Object execute(IListAlgo algo, Object... inp)
      Calls the empty case of the algorithm algo, passing to it itself as the host parameter and the given input inp as the input parameter. This method is marked as final to prevent all subclasses from overriding it. Finalizing a method also allows the compiler to generate more efficient calling code.
      Specified by:
      execute in interface IList
      Parameters:
      algo - an extrinsic operation (algorithm) on this IList.
      inp - a variable number of input parameters needed by algo to perform the computation.
      Returns:
      an Object representing the output of the computation.
    • toString

      public String toString()
      Overrides:
      toString in class Object