Card 08/ 08
All 8 cards
RecapDifficulty: Advanced1 min
What Is Hidden, From Whom, and What Still Leaks
Five things this topic established, and where each one was.
| The thing | Where |
|---|---|
private reduces the number of places a rule has to be written to one | Keeping a Field Where Only Its Owner Can Reach It |
Four access levels, and the widest of the two middle ones is protected | The Four Access Levels |
private protects the variable and not the object it points at | Why Your private List Is Not private |
| Copy on the way in as well as on the way out | Why the Same Leak Happens Through a Constructor |
extends exposes the whole parent; a field exposes what you chose | Has-a Against Is-a |
Hiding a variable is easy and hiding an object takes a copy. A class whose fields are all immutable values is encapsulated the moment they are private; a class holding collections is not, until something stops the references escaping.