# SOLID Quiz

## Question 1

What does the Single Responsibility Principle state?

A) Every function should have one line
B) A class should have only one reason to change
C) Every project should have one main file
D) A module should export one thing

<!-- ANSWER: B -->
<!-- EXPLANATION: SRP means each class/module should have one axis of change — one reason why it might need to be modified. This keeps changes localized and reduces coupling. -->

## Question 2

How does the Open/Closed Principle suggest adding new behavior?

A) By editing existing code
B) By extending (new classes, plugins) without modifying existing code
C) By copying the entire module
D) By using configuration only

<!-- ANSWER: B -->
<!-- EXPLANATION: OCP says software should be open for extension, closed for modification. Add new behavior via new code (inheritance, composition, plugins) rather than editing working code. -->

## Question 3

A Square class extends Rectangle but overrides setWidth to set both width and height. Why is this a Liskov violation?

A) Squares are not rectangles
B) Code that expects Rectangle's setWidth to only change width will get unexpected behavior
C) Square is slower
D) It uses more memory

<!-- ANSWER: B -->
<!-- EXPLANATION: LSP requires subtypes to be substitutable. Callers of Rectangle.setWidth expect only width to change. Square breaks that contract by also changing height, causing subtle bugs. -->

## Question 4

What problem does Interface Segregation address?

A) Too many small interfaces
B) Clients forced to depend on methods they don't use
C) Interfaces that are too generic
D) Slow interface resolution

<!-- ANSWER: B -->
<!-- EXPLANATION: ISP says clients shouldn't depend on interfaces they don't use. Fat interfaces force implementers to add no-op methods and create unnecessary coupling. -->

## Question 5

In Dependency Inversion, what should high-level modules depend on?

A) Low-level modules directly
B) Abstractions (interfaces)
C) Concrete implementations
D) Global singletons

<!-- ANSWER: B -->
<!-- EXPLANATION: DIP says both high-level and low-level modules should depend on abstractions. High-level modules define interfaces; low-level modules implement them. This enables swapping implementations and testing. -->

## Question 6

Which principle most directly enables easy unit testing with mocks?

A) SRP
B) OCP
C) LSP
D) DIP

<!-- ANSWER: D -->
<!-- EXPLANATION: DIP enables dependency injection. When a class receives its dependencies (e.g., a database or logger) via constructor, you can inject mocks in tests. Without DIP, hard-coded dependencies make testing hard. -->

## Question 7

<!-- VISUAL: matching -->

Match each SOLID letter to its principle name:

A) S → 1) Open/Closed Principle
B) O → 2) Dependency Inversion Principle
C) L → 3) Single Responsibility Principle
D) I → 4) Liskov Substitution Principle
E) D → 5) Interface Segregation Principle

<!-- ANSWER: A3,B1,C4,D5,E2 -->
<!-- EXPLANATION: S = Single Responsibility, O = Open/Closed, L = Liskov Substitution, I = Interface Segregation, D = Dependency Inversion. -->

## Question 8

<!-- VISUAL: matching -->

Match each principle to a code example that violates it:

A) SRP violated → 1) A class that both sends emails and formats PDFs
B) OCP violated → 2) Adding a new payment method by editing the PaymentProcessor class
C) LSP violated → 3) A Bird subclass that overrides fly() to throw (penguin can't fly)
D) ISP violated → 4) A Worker interface with eat(), sleep(), and work() — Robot implements work() but must implement no-op eat() and sleep()

<!-- ANSWER: A1,B2,C3,D4 -->
<!-- EXPLANATION: SRP: one class with multiple unrelated responsibilities (1). OCP: modifying existing class instead of extending (2). LSP: subtype not substitutable (3). ISP: client forced to implement unused methods (4). -->
