我们以这个类为例:
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
并将其与此进行比较:
public class Student{
public final String name;
public final String id;
public Student(String name, String id){
this.name = name;
this.id = id;
}
}
在我看来,不需要访问器。
这会被认为是糟糕的 OO 设计吗?