Shallow immutability and the defensive copy
A record's fields are final, but a final reference to a mutable list still lets anyone holding the same list change it. List.copyOf takes a snapshot and returns an unmodifiable list.
The object-oriented design questions interviewers use to test judgement: the four pillars, SOLID, composition over inheritance, immutability, the common patterns and the "design a class for…" prompt, with runnable proofs and links to the System Design course's pattern pages.
Change the code and press Run (Ctrl+Enter). Try to predict the output first, then break it on purpose and read the error. Your edits are saved and match the lesson page.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Refactor a class ReportService that loads data, formats it as CSV and writes it to a file into classes with one responsibility each. Show the interfaces and a main that wires them together.
Write an immutable Period class holding a start and end int day, rejecting end before start, with a withEnd method.
Write a LoggingList<E> that wraps any List<E> by composition and prints every add, exposing only add, get and size.
Explain it without notes
[Pillars] Explain the four pillars of OOP with one example each.
[Pillars] What is the difference between abstraction and encapsulation?
[SOLID] Explain the SOLID principles.
[SOLID] Give an example of a Liskov substitution violation.
[SOLID] What is dependency inversion, and how is it different from dependency injection?
[Composition] Why prefer composition over inheritance? When is inheritance right?
[Relationships] What is the difference between association, aggregation and composition?
[Immutability] How do you make a class immutable, and why bother?
[Immutability] Why can't you subclass and add fields while keeping equals correct?
[Patterns] How do you write a thread-safe Singleton, and what are its problems?
[Patterns] Factory vs Builder: when do you use each?
[Patterns] Strategy vs State?
[Patterns] Name design patterns used in the JDK.
[Design] What are coupling and cohesion, and what is the Law of Demeter?
[Design] How do you approach a "design a parking lot" question?
Expected output
LeakyTeam[name=leaky, members=[ana, bo, mallory]]
SafeTeam[name=safe, members=[ana, bo]]
safe.members().add: UnsupportedOperationException