Notice that clients of the SimpleStack class only have access to the stack through the public methods isEmpty, isFull, push and pop. The actual stack array and the pointer top are private and cannot be directly manipulated by the client. In fact it is not necessary to implement a stack using an array. We shall see how it can also be implemented using a linked structure.
From the client's point of view, details of the implementation are secondary. The primary consideration is that it provides the necessary functionality, so that it interfaces correctly with the client's program. We can express these ideas by using the Java construct of an interface. A simple interface for a Stack of objects is shown in Figure 2.2.
public interface Stack {
public boolean isEmpty();
public void push(Object item);
public Object pop();
}
|