Why are AbstractQueue and AbstractList unrelated?

During my C school days, when I implemented Queue, I implemented them on top LinkedList. So basically I had two pointers (front and back) for operations Queueon top LinkedListor better than one pointer on top of above CircularLinkedList.

I am learning Java Collections Framework, and I notice that the design completely decoupled the interfaces Listand Queue, and the implementation branches out as follows -

alt text

I think it AbstractQueueshould be subclassed somewhere inside AbstractList. Maybe not inside ArrayList, because I don't want random access to elements, but maybe inside AbstractSequentialList, hmm? (I understand, I could be completely wrong here)

+3
source share
3 answers

This is similar to what was done for flexibility of implementation: the queue should not be implemented as a list (in particular, the priority queue almost certainly represents a bunch at the bottom, which is a much more arbitrary structure than the list has to offer).

+2
source

I think the interfaces should be disjoint, but there is a link in the implementation method that you defined. The list and queue are conceptually different from the consumer when they are viewed as a black box, even if there is a connection between how you can implement them using the linked list.

+2
source

Is the Liskov replacement principle appropriate here ? AbstractQueue is NOT an abstract list, so it should not inherit it. However, an implementation may use one, but the composition is not inherited.

+1
source

Source: https://habr.com/ru/post/1746379/


All Articles