... 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.
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.