... interface. Using composition enables us to hide class List<E>’s other public methods from Queue<E>’s client code. Each Queue<E> method delegates to a List<E> method—enqueue calls List<E> method insertAtBack (Fig. 21.11, line 14), dequeue calls List<E> method removeFromFront (line 18), isEmpty calls List<E> method isEmpty (line 22) and print calls List<E> method print (line 25). For reuse, class Queue<E> is declared in package com.deitel.datastructures. Again, we do not import List<E> because it’s in the same package.

Fig. 21.11 Queue uses class List.


 1   // Fig.  21.11: Queue.java
 2   // Queue uses class List.
 3   package com.deitel.datastructures;
 4
 5   import java.util.NoSuchElementException;
 6
 7   public class Queue<E> {
 8      private List<E> queueList;
 9
10      // ...

Get Java How To Program, Late Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.