In principle, the
LinkedList class should use the getters and setters of the
Node class to access instance variables of that class. There are some hazards associated with accessing instance variables of another class directly when getters and setters are available to access those variables.
One of the hazards is that revisions of the internal details of a class could break the functionality of other classes that access those details directly. Suppose, for example, the author of the
Node class changed the name of the
next_node instance variable and revised the getters and setters accordingly. All other classes that access that variable directly would need to be revised. Classes that used the getters and setters would avoid that problem.
Another hazard is that some getters and setters perform other tasks in addition to accessing and assigning values to variables. For example, they might update counters or apply time stamps. Accessing the instance variables directly from another class would bypass that functionality.
In accordance with the above, use getters and setters to access instance variables when those getters and setters are available.