# oop & design patterns
// [23] real interview questions. Answers and sources live in the practice app.
practice this topic- What is the Singleton pattern, and when is it actually legitimate?(junior)
- Why is a naive lazy-initialized Singleton broken under concurrency? Show the failure.(mid)
- Compare the ways to make a Singleton thread-safe: synchronized getInstance, eager static init, double-checked locking, enum/holder idiom.(senior)
- Your test suite passes in isolation but fails when run together, and the culprit is a Singleton. Why do singletons poison tests, and what's the structural fix?(senior)
- Explain the Observer pattern with a real use case. What's the main pitfall in practice?(mid)
- A method has grown a switch statement over 'shipping type' repeated in three places. Which pattern fixes this, and how?(mid)
- How does the Decorator pattern add behavior without inheritance, and why is it better than subclassing here?(mid)
- 'Prefer composition over inheritance' — explain the principle with a concrete refactor where inheritance went wrong.(mid)
- What is dependency injection, and what concretely improves when you use it?(mid)
- Why is calling an overridable (or abstract) method from a constructor dangerous?(senior)
- Static vs non-static (inner) nested classes: what's the difference, and what's the memory-leak trap?(senior)
- When would you choose a TreeSet over a HashSet? What are you trading?(mid)
- Is List<String> a subtype of List<Object> in Java? Explain generic variance and the ? extends / ? super wildcards.(senior)
- What is reflection, why do frameworks depend on it, and what are its costs?(mid)
- High cohesion, loose coupling — define both, and name the smells that tell you a codebase lacks them.(mid)
- order.getCustomer().getAddress().getCity() — which principle does this chain violate, and when should you actually care?(mid)
- What is Inversion of Control — beyond just being another name for dependency injection?(senior)
- Why is global or static mutable state considered harmful? Show the concrete failure modes.(mid)
- You inherit a 6000-line class named AppManager that everything depends on. What anti-pattern is this, and how do you dismantle it without a rewrite?(senior)
- Active Record vs Data Mapper for persistence — what are the trade-offs, and what is an 'anemic domain model'?(senior)
- Tony Hoare called the null reference his 'billion-dollar mistake'. How do you design code so NullPointerExceptions stop happening?(senior)
- What does DRY actually mean — and when is duplication the better engineering choice?(mid)
- What do access modifiers give you — and why isn't a getter/setter pair for every field 'encapsulation'?(junior)