Skip to content
QuizMaker logoQuizMaker
Activity
Java Backend Interview Prep

No lessons available

CONTENTS

12. SOLID, Coupling, and Cohesion

Explain clean object-oriented design principles with Java examples.

Java Backend Interview Prep
3. OOP & DSA Revision
May 29, 2026
20
A

SOLID

PrincipleInterview Meaning
Single ResponsibilityOne class should have one reason to change
Open/ClosedOpen for extension, closed for modification
Liskov SubstitutionChild classes should be usable where parent classes are expected
Interface SegregationDo not force clients to depend on methods they do not use
Dependency InversionDepend on abstractions, not concrete low-level classes

Coupling and Cohesion

Cohesion is about how closely related responsibilities inside one module are. High cohesion is good.

Coupling is about how much one module depends on another. Low coupling is good.

Interview Framing

A good answer connects SOLID to maintainability: easier testing, lower blast radius, clearer responsibilities, and safer future changes.

Interview Scenario Practice

Scenario 1: Invoice Class Prints, Saves, and Calculates

Scenario: One Invoice class calculates totals, saves to DB, and prints PDFs.

Strong answer: This violates Single Responsibility. Split calculation, persistence, and printing into focused collaborators.

Why it works: Each class then has fewer reasons to change and becomes easier to test.

Common mistake: Thinking SRP means one method per class. It means one reason to change.

Scenario 2: Adding a New Payment Type

Scenario: Every new payment method requires editing a large if-else chain.

Strong answer: Apply Open/Closed and Dependency Inversion by depending on a PaymentProcessor interface and adding new implementations.

Why it works: New behavior is added through extension instead of repeated modification of existing code.

Common mistake: Hiding the if-else in another class without changing the design pressure.

Scenario 3: Fat Interface

Scenario: A printer class is forced to implement scan() and fax() methods it cannot support.

Strong answer: This violates Interface Segregation. Split the interface into smaller capabilities like Printable, Scannable, and Faxable.

Why it works: Implementations only depend on methods they actually use.

Common mistake: Throwing UnsupportedOperationException from many unused interface methods.

Share this article

Test your knowledge

Take a quick quiz based on this chapter.

mediumJava Backend Interview Prep
Quiz: SOLID and Design Quality
8 questions8 min

0 comments

Please login to comment.
No comments yet.
Lesson 2 of 5 in 3. OOP & DSA Revision
Previous in 3. OOP & DSA Revision
11. OOP Relationships: Association, Aggregation, and Composition
Next in 3. OOP & DSA Revision
13. Collections Comparison Cheat Sheet
Back to Java Backend Interview Prep
Back to moduleCategories