Concept
Keep an object's fields private and expose behaviour through methods, so the object controls its own invariants. Callers get what they need without being able to leave it in a broken state.
The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.
A few lines that show Encapsulation doing its job.
public class Account {
private long balanceCents;
public void withdraw(long cents) {
if (cents <= 0) throw new IllegalArgumentException("amount must be positive");
if (cents > balanceCents) throw new InsufficientFundsException(balanceCents, cents);
balanceCents -= cents;
}
public long balanceCents() { return balanceCents; }
}Generating a getter and setter for every field, which is public fields with extra steps. If any code can call setBalance(-500), the class is not guarding anything.
Your roadmap puts these before Encapsulation, unless you already know them.
Once a session shows you understand Encapsulation, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.
Topics that build on Encapsulation.