📐 Section 18 · 22 questions

OOP and SOLID

22 interview questions and answers in the OOP and SOLID section.

Questions in this section

  1. What is Single Responsibility Principle and How to Apply It
  2. Give an Example of Single Responsibility Principle Violation
  3. What is Open Closed Principle
  4. How to Refactor Code That Violates Open Closed Principle
  5. What is Liskov Substitution Principle
  6. Give an Example of Liskov Substitution Principle Violation
  7. What is Interface Segregation Principle
  8. What is Dependency Inversion Principle
  9. Why Do We Need SOLID Principles at All
  10. What is composition and inheritance
  11. When is it better to use composition instead of inheritance
  12. What is delegation in OOP
  13. How is Single Responsibility related to cohesion
  14. What happens if a class has multiple reasons to change
  15. How does SOLID help in code testing
  16. How is Dependency Inversion related to Dependency Injection
  17. What is Law of Demeter (principle of least knowledge)
  18. How to refactor God Object
  19. How do SOLID principles help when extending functionality
  20. Can you follow all SOLID principles at once
  21. How to determine if a class has single responsibility
  22. What anti-patterns contradict SOLID principles

Study navigator

22 essential questions and deep-dive architectural analyses for Junior 🟢, Middle 🟡, and Senior 🔴 Java Software Engineers and Architects.


📋 Table of Contents

# Question Difficulty
01 What is Single Responsibility Principle and How to Apply It ⭐
02 Give an Example of Single Responsibility Principle Violation ⭐⭐
03 What is Open Closed Principle ⭐⭐
04 How to Refactor Code That Violates Open Closed Principle ⭐⭐
05 What is Liskov Substitution Principle ⭐⭐
06 Give an Example of Liskov Substitution Principle Violation ⭐⭐
07 What is Interface Segregation Principle ⭐⭐
08 What is Dependency Inversion Principle ⭐⭐
09 Why Do We Need SOLID Principles at All ⭐
10 What is Composition and Inheritance ⭐
11 When is It Better to Use Composition Instead of Inheritance ⭐⭐
12 What is Delegation in OOP ⭐
13 How is Single Responsibility Related to Cohesion ⭐⭐
14 What Happens If a Class Has Multiple Reasons to Change ⭐⭐
15 How Does SOLID Help in Code Testing ⭐⭐
16 How is Dependency Inversion Related to Dependency Injection ⭐⭐
17 What is Law of Demeter (Principle of Least Knowledge) ⭐⭐
18 How to Refactor God Object ⭐⭐⭐
19 How Do SOLID Principles Help When Extending Functionality ⭐⭐
20 Can You Follow All SOLID Principles at Once ⭐⭐
21 How to Determine If a Class Has Single Responsibility ⭐⭐
22 What Anti-Patterns Contradict SOLID Principles ⭐⭐

🗺️ Topic Dependency Map

                    ┌──────────────────────────────────────────┐
                    │       THE 5 SOLID PILLARS (01-08)        │
                    │   01-02. Single Responsibility (SRP)     │
                    │   03-04. Open/Closed Principle (OCP)     │
                    │   05-06. Liskov Substitution (LSP)       │
                    │   07.    Interface Segregation (ISP)     │
                    │   08.    Dependency Inversion (DIP)      │
                    └──────────────────┬───────────────────────┘
                                       │
            ┌──────────────────────────┼──────────────────────────┐
            ▼                          ▼                          ▼
    ┌───────────────┐        ┌───────────────┐        ┌────────────────────┐
    │ OOP REUSE &   │        │ COHESION &    │        │ TESTABILITY & DI   │
    │ DESIGN (10-12)│        │ REFACTORING   │        │ (15-16)            │
    │ 10. Comp/Inher│        │ (13-14, 18, 21)│        │ 15. Testing Power  │
    │ 11. Favor Comp│        │ 13. Cohesion  │        │ 16. DIP vs DI & IoC│
    │ 12. Delegation│        │ 14. Mult. Reas│        └────────┬───────────┘
    └───────┬───────┘        │ 18. God Object│                 │
            │                │ 21. Detect SRP│                 │
            │                └───────┬───────┘                 │
            │                        │                         │
            └────────────────────────┼─────────────────────────┘
                                     ▼
                    ┌──────────────────────────────────────────┐
                    │   REAL-WORLD ARCHITECTURE & ANTI-PATTERNS│
                    │   09. Why SOLID Matters in Production    │
                    │   17. Law of Demeter (Least Knowledge)   │
                    │   19. Safe Extensibility                 │
                    │   20. Practical Trade-offs & Balance     │
                    │   22. Anti-Patterns (Spaghetti, God Obj) │
                    └──────────────────────────────────────────┘

🟢 Junior Track (Core Concepts & Fundamentals)

🟡 Middle Track (Code Smells & Refactoring Patterns)

🔴 Senior Track (Enterprise Refactoring & Architecture Trade-offs)