What is the relationship between a Queue class and Node class is it inheritance, Association or Aggregation?

371 views Asked by At

if im using the node class in the Queue like

Node tmpNode = new Node();

What would that relationship be called?

2

There are 2 answers

0
svjn On BEST ANSWER

Here you create the Node object inside Queue. This means the Node object's existence completely depends upon Queue object's existence. If Queue object is destroyed, then there is no way for Node object to survive.

In Aggregation, the life of an object may not depend on its container. That means, the referenced object may survive even the container is destroyed.

Hope this link gives you better understanding on Aggregation and Composition with proper Java code samples.

0
Bruce On

It is composition. A queue consists of 0 to many nodes. If the queue is deleted, all the nodes are deleted. A node would not exist outside of the queue (if I have your meaning right).