A friend of mine just brought up that I should use getters for classes, is this considered good practice or not? I couldn't find the answer elsewhere.
And how about Setters for classes? Does that even exist?
Thanks for your input.
public class Movement {
private Player p;
public Movement(Player p) {
this.player = p;
}
// methods
}
public class Player {
/**
* The movement class that handles all players movements
*/
private Movement movement;
public Player() {
this.movement = new Movement(this);
}
public Movement getMovement() {
return this.movement;
}
}
@people saying duplicate question This is not simple variables that require protection by being private. This is about the habit of adding a getter for a class, which I don't get since the class is already public.