Before Re-factoring
class Person{
Set courses;
Set getCourses(){
return courses;
}
void setCourses(){...}
}
After Re-factoring
class Person{
Set courses;
Set getCourses(){
return Collections.unmodifiableSet(courses);
}
void addCourse(){...}
void removeCourse(){...}
}
Benefits:
1.
Person will know it when
courses changes.
2. Coupling between clients which call
Person and
courses will be reduced.