Let’s take this class as an example:
public class Student{
private String name;
private String id;
public Student(String name, String id){
this.name = name;
this.id = id;
}
... getters and setters for both fields
and compare it to this:
public class Student{
public final String name;
public final String id;
public Student(String name, String id){
this.name = name;
this.id = id;
}
}
There is in my opinion no need for the accessors.
Would this be considered bad OO design?
This is a loaded question.
Unfortunately, good (or bad) design is 100% dependent on how it is going to be used.
As a rule of thumb, it is a good idea to keep member variables private, just so that the Object model is in control of their access. This implies the first approach is better.
BUT
if the values never change, what’s the point? Why bother writing setters if they will never be used?
So, which one is better? As I mentioned above, that depends on what you are doing this for. If it’s for an assignment for class, I would go with the first one. Your teacher will like that more, as it is more “textbook”.
So, if this is a personal project or for work where you can take advantage of future releases, I would go with a cross between the two:
This approach is safe, because the member fields are private, and there isn’t the “code smell” of unused methods. This is also fairly extensible, as you can quite easily add the setters if your requirements ever change and you need to modify the fields.