1.不要将集合对象的类型直接对外暴露
例如
CourseSession
不要提供
public List<Student> getAllStudents()
转而用get代替
public Student get(int index)()
本文讨论了如何在不直接暴露集合对象类型的前提下,通过提供特定方法(如 get 方法)来安全地访问集合内的元素,以此保护内部数据结构。
1.不要将集合对象的类型直接对外暴露
例如
CourseSession
不要提供
public List<Student> getAllStudents()
转而用get代替
public Student get(int index)()

被折叠的 条评论
为什么被折叠?