Skip to main content
InterviewHubPRO
HomeTracksSection 57: SOLID & OOP Principles (50 Qs)
Section 57 of 6450 Questions (1 Per Page)

SOLID Principles, Object-Oriented Design & Clean Code Master Interview Bank

SOLID Principles (SRP, OCP, LSP, ISP, DIP), High Cohesion & Low Coupling, Composition over Inheritance, Law of Demeter, Code Smells, and Architecture Testing with ArchUnit.

Curriculum Roadmap & Learning Path

3 Stages
Tip: Click any stage card above to instantly filter the question bank to that topic.3 Connected Milestones
50 of 50 Qs

Part 1: Core SOLID Principles & Fundamentals (1 - 10)

10 Questions
1
JuniorCode#solid-principles#Core SOLID Principles

What are the SOLID Principles and why are they fundamental to software engineering?

SOLID is an acronym for 5 object-oriented design principles introduced by Robert C. Martin (Uncle Bob): S - Single Responsibility Principle (SRP): A class should have one, and only one, reason to change • O - Open/Closed Principle (OCP): Software entities should be open for extension, but closed for modification.

2
JuniorCode#solid-principles#Core SOLID Principles

How do you implement the Single Responsibility Principle (SRP) in practice?

A class should focus on a single concern: Violation: An Invoice class that calculates taxes, prints invoices to PDF, and saves invoices to a PostgreSQL database (3 reasons to change!) • Refactoring • Invoice: Manages line items and calculations • InvoicePdfGenerator: Handles PDF formatting.

3
Junior#solid-principles#Core SOLID Principles

How do you implement the Open/Closed Principle (OCP) using Polymorphism?

You should be able to add new functionality without modifying existing, tested source code: Violation: Using a massive switch(paymentType) statement inside processPayment() • Refactoring: Define a PaymentMethod interface; implement CreditCardPayment, PayPalPayment, and ApplePayPayment as independent classes.

4
Junior#solid-principles#Core SOLID Principles

What is the Liskov Substitution Principle (LSP) and what is the classic Rectangle-Square violation?

Subclasses must adhere to the behavioral contract of their parent class: The Rectangle-Square Violation • Square inherits from Rectangle • In Square, setting width automatically sets height to maintain a square • A function expecting a Rectangle sets width = 5 and height = 10 and expects area to be 50.

5
Junior#TypeScript

What is the Interface Segregation Principle (ISP)?

Many client-specific, granular interfaces are better than one bloated, "fat" interface: Violation: A monolithic Worker interface with work(), eat(), and sleep() • Refactoring: Split into Workable and Feedable interfaces.

6
Most AskedJunior#Dependency Injection

What is the Dependency Inversion Principle (DIP) and how does it differ from Dependency Injection (DI)?

Dependency Inversion Principle (DIP - The Design Principle): High-level business logic modules should not depend on low-level modules (e.g • Dependency Injection (DI - The Implementation Pattern): A technique where an object receives its dependencies from the outside (e.g. passed via.

7
Junior#solid-principles#Core SOLID Principles

What is High Cohesion and Low Coupling, and how do they balance software design?

High Cohesion: Elements within a module belong together and focus on performing one single, well-defined task • Low Coupling: Modules are loosely connected and independent; changes to one module do not ripple through or break other modules.

8
Most AskedJunior#solid-principles#Core SOLID Principles

Why does Composition over Inheritance prevent the Fragile Base Class problem?

Inheritance is the tightest coupling in OOP because subclasses depend on the internal implementation details of the superclass. A change in the parent class can silently break subclass invariants (Fragile Base Class). Composition delegates behavior via interfaces, keeping boundaries clean and independently testable.

9
Senior#solid-principles#Core SOLID Principles

What is the Law of Demeter (Principle of Least Knowledge) and how do you spot train-wreck code?

A method should only call methods on: Itself (this) • Its parameters • Objects it instantiated directly • Its direct member fields.

10
Junior#solid-principles#Core SOLID Principles

Explain the Tell, Don't Ask principle and how it avoids Anemic Domain Models?

Rather than asking an object for its data, performing logic outside, and setting the data back (Ask), tell the object what to do and let it manipulate its own internal state, encapsulating business rules.

Part 2: Object-Oriented Design, Code Smells & Refactoring (11 - 24)

14 Questions
11
Junior#solid-principles#Object-Oriented Design

What is the DRY (Don't Repeat Yourself) principle vs Accidental Duplication?

DRY states: Every piece of knowledge must have a single, unambiguous representation within a system.: Crucial Distinction: Code that looks identical but changes for different business reasons is Accidental Duplication.

12
Junior#solid-principles#Object-Oriented Design

What are YAGNI and KISS principles and how do they prevent over-engineering?

YAGNI (You Aren't Gonna Need It): Never write code or create abstractions based on speculation about future requirements • KISS (Keep It Simple, Stupid): Systems work best when kept simple rather than complicated with unnecessary layers.

13
Junior#solid-principles#Object-Oriented Design

What is an Anemic Domain Model vs a Rich Domain Model?

Anemic Domain Model: Classes contain only getters/setters with zero business logic (pure data bags); all business rules reside in procedural • Rich Domain Model: Domain entities encapsulate both data and business logic, defending their own invariants.

14
Mid#solid-principles#Object-Oriented Design

How do you defend Domain Invariants inside Domain Entities?

A domain invariant is a business rule that must always be true throughout an entity's lifecycle. Protect invariants by: Making constructors private or validating all invariants upon creation • Eliminating public setters • Exposing intention-revealing methods that enforce validation.

15
Junior#solid-principles#Object-Oriented Design

What is Command Query Separation (CQS) at the class and method level?

Every method should either be: A Command: Mutates system state, returns void • A Query: Returns a value, has zero side-effects on system state.

16
Mid#solid-principles#Object-Oriented Design

How do you identify the "God Object" Code Smell and how do you refactor it using SRP?

A God Object knows too much or does too much (thousands of lines, dozens of dependencies). Refactor by grouping methods around distinct business actors and extracting cohesive single-purpose classes.

17
Junior#solid-principles#Object-Oriented Design

What is Primitive Obsession and how do Value Objects resolve it?

Relying on raw primitives (string email, decimal amount) rather than domain models. A Value Object (EmailAddress, Money) encapsulates validation, formatting, and immutability.

18
Junior#solid-principles#Object-Oriented Design

What is Feature Envy and how do you resolve it?

Occurs when a method in class A accesses getters of class B more than its own data. Resolve by moving the method into class B where the data naturally lives.

19
Mid#solid-principles#Object-Oriented Design

How do you design for Testability using the Dependency Inversion Principle?

High-level classes depend on interface abstractions injected via constructors. In unit tests, inject test doubles (mocks/stubs) without spinning up databases, file systems, or network sockets.

20
Junior#TypeScript

What is Interface Pollution and how does the Interface Segregation Principle prevent it?

Occurs when an interface accumulates dozens of unrelated methods. Clients are forced to implement dummy methods they never use. Segregate into smaller, role-focused interfaces (Readable, Writable, Closeable).

21
Mid#solid-principles#Object-Oriented Design

How does the Liskov Substitution Principle apply to Exception Contracts?

Subclasses cannot throw broader checked exceptions than their superclasses. A subclass method must honor the exception contract of the base abstraction to prevent unexpected crashes.

22
Junior#solid-principles#Object-Oriented Design

What are Preconditions and Postconditions in Design by Contract (LSP)?

Preconditions: Cannot be strengthened in a subtype (cannot demand stricter inputs) • Postconditions: Cannot be weakened in a subtype (cannot guarantee less outputs).

23
Junior#solid-principles#Object-Oriented Design

What is Shotgun Surgery vs Divergent Change?

Divergent Change: A single class is modified for multiple unrelated reasons (violates SRP) • Shotgun Surgery: A single business change forces dozens of edits across many different classes.

24
Mid#solid-principles#Object-Oriented Design

How do you refactor Legacy Code toward SOLID using Automated Characterization Tests?

Before refactoring legacy code with zero tests, write Characterization Tests that capture the current actual behavior of the system (bugs and all) to provide a safety net.

Part 3: Enterprise Architecture, Package Design & Enforcement (25 - 35)

26 Questions
25
Senior#System Design#Microservices

How do SOLID principles apply at the Microservices boundary level?

SRP: A service owns a single business capability • OCP: Extend service features via event listeners rather than modifying existing APIs • DIP: Services communicate via standardized API schemas and contracts.

26
Most AskedSenior#Closures & Scope#System Design

Explain the Common Closure Principle (CCP) and Common Reuse Principle (CRP)?

CCP: Classes that change together should be packaged together in the same module • CRP: Classes that are not used together should not be packaged together.

27
Senior#CLI#System Design

What is the Acyclic Dependencies Principle (ADP) in enterprise package architecture?

The dependency graph of packages must contain no cycles (no mutual A -> B -> A dependencies). Break cycles by applying DIP and introducing an interface.

28
Senior#State Management#System Design

What is the Stable Abstractions Principle (SAP) and Stable Dependencies Principle (SDP)?

SDP: Depend in the direction of stability (depend on modules that are harder to change) • SAP: A stable module should also be abstract (interfaces/abstract classes) so it can be extended.

29
Most AskedSeniorCode#CI/CD & DevOps#System Design

How do you enforce SOLID and Architectural Rules in CI/CD using ArchUnit or NetArchTest?

Write automated architectural fitness tests that fail in CI/CD if developers violate SOLID rules (e.g. domain layer depending on infrastructure, or circular package dependencies).

30
Senior#TypeScript#System Design

How do you apply SOLID in Functional and Modern Multi-Paradigm Languages (TypeScript, Go, Rust)?

In languages without classic class inheritance, SOLID is applied via function composition, traits (Rust), implicit interfaces (Go), and structural typing (TypeScript).

31
Senior#System Design

What is the Rule of Three in software refactoring and avoiding Premature Abstraction?

Don't extract a shared abstraction when you see code duplicated once. Wait until you write it for the third time so you have enough data points to create the correct abstraction.

32
Senior#Forms#System Design

How does Encapsulation differ from Information Hiding?

Encapsulation: Bundling data with methods that operate on that data • Information Hiding: Concealing design decisions and data structures behind stable interfaces to protect clients from change.

33
Senior#Forms#Performance

What is Static vs Dynamic Polymorphism and what are their performance trade-offs?

Dynamic Polymorphism: Virtual method dispatch via v-tables at runtime; flexible but adds pointer indirection • Static Polymorphism: Generics and templates resolved at compile-time; zero runtime overhead and can be inlined.

34
Senior#System Design

How do you refactor an enterprise Payment Processing system adhering to all 5 SOLID principles?

SRP: Separate payment validation, gateway API calls, and invoice generation into distinct classes • OCP: Add new payment gateways (Stripe, PayPal, Crypto) by implementing PaymentGateway interface without modifying existing checkout code • LSP: Ensure all gateways return standardized result types and honor timeout contracts.

35
Senior#Forms#Performance

When does strict adherence to SOLID harm software development velocity and performance?

Blindly creating 5 interfaces and factories for simple CRUD operations creates excessive indirection and mental fatigue. Balance SOLID with pragmatism: apply principles where business logic actually changes.

36
Senior#System Design

Single Responsibility Principle (SRP) and the "Reason to Change": Actor-driven responsibilities.

Robert C. Martin ("Uncle Bob") refined SRP: "A module should be responsible to one, and only one, actor (stakeholder/user group)": The Violation Example: An Employee class containing calculatePay() (owned by CFO/Finance), reportHours() (owned by COO/Operations), and save().

37
SeniorCode#System Design

Open/Closed Principle (OCP) via Strategy and Plugin Architectures.

"Software entities should be open for extension, but closed for modification": When adding a new shipping carrier (DHL) to an e-commerce platform, you should never open and edit existing shipping calculation code with a new • Plugin / Strategy Architecture.

38
Senior#System Design

Liskov Substitution Principle (LSP) Contracts: Preconditions, Postconditions, and Invariants.

Formulated by Barbara Liskov: Subtypes must be substitutable for their base types without altering program correctness.: Preconditions cannot be strengthened: If base method process(amount) accepts any positive number (> 0), a subclass cannot demand amount >= 100.

39
Senior#TypeScript#System Design

Interface Segregation Principle (ISP) vs Fat Interfaces.

"Clients should not be forced to depend upon interfaces that they do not use": Fat Interface Anti-Pattern: An AllInOnePrinter interface declaring print(), scan(), fax(), and staple() • Role Interfaces: Split into lean, granular capabilities • Printer { print() } • Scanner { scan() }.

40
Most AskedSenior#Dependency Injection#System Design

Dependency Inversion Principle (DIP) vs Inversion of Control (IoC) vs Dependency Injection (DI).

Clarifying the three frequently confused terms: DIP (Architectural Principle): High-level business logic modules must not depend on low-level implementation modules (databases, APIs) • IoC (Design Pattern / Concept): Inverting the traditional control flow.

41
Senior#System Design#Microservices

SOLID in Microservices Architecture.

Applying object-oriented principles to distributed systems: SRP in Microservices: Each microservice owns a single business capability and one bounded context database • OCP via Event-Driven Architecture: An Order Service emits an OrderPlaced event to Kafka.

42
Senior#System Design

SOLID in Functional Programming.

How SOLID manifests in functional languages (Clojure, Haskell, Elixir, Scala): SRP: Pure functions that do exactly one thing: accept input, return output, zero side effects • OCP: Higher-order functions • LSP: Strong algebraic type systems where sum types and pattern matching guarantee exhaustiveness.

43
Senior#System Design

Refactoring God Classes to SRP: Facades and Delegation.

Refactoring a 5,000-line monolithic UserManager class: Identify cohesive clusters of methods • Auth & Passwords -> Extract to AuthenticationService • Email Notifications -> Extract to UserEmailNotifier • Profile Billing -> Extract to UserSubscriptionService.

44
SeniorCode#System Design

The Circle-Ellipse and Square-Rectangle Dilemma in LSP.

In mathematics, a Square is a special type of Rectangle (width = height). In Object-Oriented Programming, modeling Square extends Rectangle violates LSP.

45
Senior#TypeScript#System Design

Interface Pollution and YAGNI: Detecting premature abstraction.

Interface Pollution Anti-Pattern: Creating an IUserService interface for every single UserService when there is only ever one concrete • Creates indirection, requires clicking through two files in IDEs, and provides zero business value.

46
Senior#System Design

DIP in Clean Architecture / Hexagonal Architecture (Ports and Adapters).

The Core Invariant: The domain layer (Entities and Use Cases) sits at the center and knows nothing about databases, web frameworks, or • Ports (Interfaces): Defined inside the Domain layer (e.g. UserRepository, EmailSender).

47
SeniorCode#Testing#System Design

Testing Benefits of SOLID.

Fast Unit Tests: When classes follow SRP, they have few dependencies, allowing unit tests to run in microseconds without booting heavy • Trivial Mocking via DIP: Because dependencies are injected as interfaces, test suites can pass in-memory fake repositories or mock gateways instantly.

48
Senior#System Design

Anti-Patterns Violating SOLID: Shotgun Surgery vs Divergent Change.

Divergent Change (Violates SRP): When one class has to be modified in different ways every time different business requirements change (e.g • Shotgun Surgery (Opposite of SRP): When a single business change requires making dozens of small edits scattered across 15 different classes.

49
Senior#System Design

SOLID and Concurrency: Thread safety invariants and immutable value objects.

In multi-threaded environments, mutable state violates class invariants under concurrent access: Immutable Value Objects: Making domain entities immutable (e.g. record in Java/C#, frozen objects in TypeScript) guarantees that class state can.

50
Most AskedSenior#System Design

Pragmatic Architecture: Balancing SOLID with KISS and YAGNI.

Architecture is about trade-offs, not dogma: KISS (Keep It Simple, Stupid): Favor simple, readable code over clever abstractions • YAGNI (You Aren't Gonna Need It): Do not build generalized abstract plugin architectures for features that might never be built • The Pragmatic Guideline: Start with simple, cohesive procedural code.