Forget about data structures, DTOs, POJOs, and anemic objects.
TL;DR: Avoid external manipulation
-
Encapsulation Violation
-
Anemic Models
- Change the visibility of your attributes from public to private.
public class Song {
String artistName;
String albumName;
}
public class Song {
// 1- Change the visibility of your attributes from public to private
private String artistName;
private String AlbumName;
// We cannot access attributes until we add methods
}
[X] Semi-Automatic
We can change the visibility with an IDE or text editor.
This is not a safe refactor.
Existing dependencies may break.
We can change encapsulated code easily.
The code is not repeated.
Some languages don't have visibility options.
- Anemic
Refactoring 001 - Remove Setters
This article is part of the Refactoring Series.