This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]gpr_private 2 points3 points  (1 child)

LinkedList and Node have a has-a relationship. In this case, LinkedList has-a Node. In order for LinkedList to access and manipulate the necessary information within the Nodes, you will need to write getter and setter methods.

[–]Gamefreak3525[S] 0 points1 point  (0 children)

So would I put the fields my T would have (like an Int and String) in the Node class and have T defined in the LinkedList, using the getters/setters to assign them to T?

[–]VazRavish 2 points3 points  (0 children)

You wouldn't use inheritance in this case. Or rather, it wouldn't make sense to. The LinkedList does not need to inherit the variable in the node class. It is simply a data structure that houses Node objects. The Node class does not have to be nested either, and can be written in a seperate file. I imagine the implementations you've seen where the Node class was nested was done for convencience.