📐 Section 18 · 22 questions
OOP and SOLID
22 interview questions and answers in the OOP and SOLID section.
Questions in this section
- What is Single Responsibility Principle and How to Apply It
- Give an Example of Single Responsibility Principle Violation
- What is Open Closed Principle
- How to Refactor Code That Violates Open Closed Principle
- What is Liskov Substitution Principle
- Give an Example of Liskov Substitution Principle Violation
- What is Interface Segregation Principle
- What is Dependency Inversion Principle
- Why Do We Need SOLID Principles at All
- What is composition and inheritance
- When is it better to use composition instead of inheritance
- What is delegation in OOP
- How is Single Responsibility related to cohesion
- What happens if a class has multiple reasons to change
- How does SOLID help in code testing
- How is Dependency Inversion related to Dependency Injection
- What is Law of Demeter (principle of least knowledge)
- How to refactor God Object
- How do SOLID principles help when extending functionality
- Can you follow all SOLID principles at once
- How to determine if a class has single responsibility
- 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
🗺️ 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) │
└──────────────────────────────────────────┘
🎯 Recommended Study Tracks
🟢 Junior Track (Core Concepts & Fundamentals)
- Step 1: The 5 SOLID Definitions — 01. What is Single Responsibility Principle and How to Apply It, 03. What is Open Closed Principle, 05. What is Liskov Substitution Principle, 07. What is Interface Segregation Principle, 08. What is Dependency Inversion Principle
- Step 2: Core OOP Principles — 10. What is Composition and Inheritance, 12. What is Delegation in OOP
- Step 3: Why SOLID Matters — 09. Why Do We Need SOLID Principles at All
🟡 Middle Track (Code Smells & Refactoring Patterns)
- Step 1: Code Smells & Violations — 02. Give an Example of Single Responsibility Principle Violation, 04. How to Refactor Code That Violates Open Closed Principle, 06. Give an Example of Liskov Substitution Principle Violation
- Step 2: Architecture & Cohesion — 11. When is It Better to Use Composition Instead of Inheritance, 13. How is Single Responsibility Related to Cohesion, 14. What Happens If a Class Has Multiple Reasons to Change
- Step 3: Testing & Demeter — 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)
🔴 Senior Track (Enterprise Refactoring & Architecture Trade-offs)
- Step 1: Large-Scale Refactoring — 18. How to Refactor God Object, 21. How to Determine If a Class Has Single Responsibility
- Step 2: Practical Pragmatism vs Overengineering — 19. How Do SOLID Principles Help When Extending Functionality, 20. Can You Follow All SOLID Principles at Once
- Step 3: Anti-Pattern Catalog — 22. What Anti-Patterns Contradict SOLID Principles