Design & Practices interview questions
65 Design & Practices interview questions with answers, from junior to mid level.
Foundations
- What is object-oriented programming (OOP) in one sentence?
- Which list contains the four classic pillars of OOP?
- Library vs framework: what is the key difference?
- In software, what is a 'dependency'?
- What is a bug, and what is debugging?
- What is a code review?
- What is SOLID?
- What is the 'Gang of Four' (GoF)?
- What is 'technical debt'?
- Explain what a class, an object, a field and a method are to a beginner.
Core
- The Single Responsibility Principle says a class should…
- In the test pyramid, which tests should you have the most of?
- The TDD cycle is…
- Good modular design aims for…
- Under Semantic Versioning, you remove a public function from a library at version 2.4.1. The next version is…
- What is the relationship between a class and an object?
- What does encapsulation mean in OOP?
class Dog(Animal):expresses which relationship?- What is polymorphism?
- What happens if you try
Shape()whenShapeis an abstract base class with an@abstractmethod area()? - What does the DRY principle say?
- What is a design pattern?
- What is refactoring?
- In Git, what is the difference between
commitandpush? - Why do developers create a Git branch for a new feature?
- What is a merge conflict?
- What does YAGNI ('You Aren't Gonna Need It') advise?
- The classic GoF design patterns are grouped into which three categories?
- Which is an anti-pattern known as the "God object" (or God class)?
- What is a design pattern, and why do interviewers ask about them?
Intermediate
- Which change best follows the Open/Closed Principle?
SquareextendsRectangle, andset_width()on a square also changes its height. Code that sets width=2, height=5 and expects area 10 breaks. Which principle is violated?- An interface
Workerhaswork(),eat()andsleep(). ARobotmust implementeat()withraise NotImplementedError. Which principle suggests a fix? - Dependency Inversion means…
- When is Builder a better fit than Factory?
- What is the main criticism of the Singleton pattern?
- What problem does the Repository pattern solve?
- What is the main benefit of dependency injection?
- Which pattern is this?
- Which pattern fits 'notify email, analytics and inventory services whenever an order is placed'?
- You must use a third-party SMS client whose interface differs from your
Notifier.send(to, text). Which pattern? - 'Favor composition over inheritance' mainly helps avoid…
- What should a unit test usually mock?
- Why do immutable objects simplify concurrent code?
- Which pattern provides a single simplified entry point to a complex subsystem (e.g.
VideoConverter.convert(file, "mp4")hiding codecs, buffers, muxers)? - Why should you avoid
git rebaseon a branch others have already pulled? - A class has 3,000 lines and handles HTTP parsing, billing rules and PDF generation. This code smell is called…
- Explain SOLID with a short example for each letter.
- How do you approach a code review (as reviewer)?
- What is the difference between Factory Method and Abstract Factory?
- Which pattern does
new BufferedReader(new FileReader("a.txt"))illustrate? - Which pattern is behind
list.sort(Comparator.comparing(Person::getAge))? - What is the Template Method pattern?
- Which pattern describes Spring wrapping your bean to add transactions, caching or security without changing its code?
- Servlet filters and Spring Security's filter chain are examples of which pattern?
- Which pattern lets you treat a single object and a group of objects in a uniform way (a tree, like folders containing files and folders)?
- What does the MVC pattern separate?
- What is the difference between a DAO and a Repository?
- Which design patterns do you actually use in Java/Spring projects, and where?
Advanced
- How does the GoF Decorator pattern differ from inheritance for adding behavior?
- Which line violates the Law of Demeter ('talk only to your immediate friends')?
- Which pattern makes undo/redo and job queues natural?
- You inherit a 2,000-line legacy module with no tests and must change it. How do you proceed safely?
- Which is the safest way to write a thread-safe Singleton in Java?
- The JVM caches
Integerobjects from -128 to 127 and reuses string literals from the string pool. Which pattern is this?