Skip to content
Discussion options

You must be logged in to vote

🧱 SOLID Principles in Java

SOLID is an acronym for five design principles that help developers write clean, scalable, and maintainable object-oriented code.


1️⃣ S — Single Responsibility Principle (SRP)

A class should have only one reason to change.

  • Meaning: Each class should do one thing and do it well.
  • Example:
    class InvoicePrinter {
        void print(Invoice invoice) { /* printing logic */ }
    }
    
    class InvoiceCalculator {
        double calculateTotal(Invoice invoice) { /* calculation logic */ }
    }

2️⃣ O — Open/Closed Principle (OCP)

Software entities should be open for extension but closed for modification.

  • Meaning: You should be able to add new functionality without changing existin…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by HARSHITH-MV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants