Earlier quoted context omitted.
If you ever want to change the implementation of Article, you'd break anyone that was using that part of your API. If you use getters, you can change your implementation without breaking the consumers of your API. For instance, let's say that you don't want to store the author's name as a string anymore, and want to store a reference to an Author object. If you have a getAuthor() method, you can change it from a simp…
> If you ever want to change the implementation of Article, you'd break anyone that was using that part of your API. If you use getters, you can change your implementation without breaking the consumers of your API. Then it wouldn't be immutable, if I can change the implementation I can also create a mutable version. Edit example public class Article { private final String title; private final String author; private…
public class Article {
private final Author author;
...
public String getAuthor() {
return author.getName();
}
}
Also, your first class isn't fully immutable—getTags should be implemented as follows: /**
* @return Unmodifiable list of tags
*/
public List getTags() {
return Collections.unmodifiableList(tags);
}