The Stack interface definition

  • Important facts:

    1. The stack only defines a behavior on the access of the data stored in a stack:

      • pop( ) must return the earliest item that was pushed

    2. The stack does not specify how the data must be stored

    3. There are different ways to implement the same behavior !!!

  • To accommodate different stack implementations, we can define a Stack interface

  • Then any class that implements the behavior (= methods) in the Stack interface can be used as a Stack "object":

      Stack a = new ClassThatImplementsStack() ;