Ensuring proper encapsulation
medium 40 minPrivate fields are the start, not the end.
Watch lesson4:46
What each level should show
The same question is judged differently for mid, senior and staff.
Junior
Must show
- Private fields, checks in the constructor
- Explains what a defensive copy is
- Knows that strings need none
Will be probed on
- Why not a public field?
- What does your getter return?
Stands out
Notices the leak in their own getter.
Mid
Must show
- Copies in and out, copy before check
- Actions instead of setters
- View or snapshot, with the difference
Will be probed on
- Two linked fields
- Shallow copies
Stands out
Replaces a getter by the question behind it.
Senior
Must show
- Side doors: callbacks,
thisescape, subclasses, deserialization - Atomic check and act, private lock
- Cost of copies with numbers
Will be probed on
- Copy on write
- Reentrant listeners
Stands out
States the invariants before the first line of code.
- Side doors: callbacks,
Staff
Must show
- Closes leaks in a large code base without an outage
- Decides where sealing pays and where a plain value is enough
- Guards with tests and lint rules
Will be probed on
- 60 callers
- Is it security?
Stands out
Moves the border to the module when classes are the wrong size.