Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 1.17 KB

File metadata and controls

30 lines (21 loc) · 1.17 KB

SOLID Principles in Java

This project demonstrates the 5 SOLID principles of Object-Oriented Programming using Java.
Each principle is implemented in its own package with simple, real-world inspired examples.


📌 SOLID Principles Covered

1. Single Responsibility Principle (SRP)

  • A class should have only one reason to change.
  • Example: Separation of InvoicePrinter and InvoiceSaver from Invoice.

2. Open/Closed Principle (OCP)

  • Classes should be open for extension but closed for modification.
  • Example: Adding new Shape types without modifying existing code.

3. Liskov Substitution Principle (LSP)

  • Subtypes must be substitutable for their base types.
  • Example: Dog and Cat can be used wherever Animal is expected.

4. Interface Segregation Principle (ISP)

  • Clients should not be forced to depend on methods they do not use.
  • Example: Separate interfaces for Printer, Scanner, Fax.

5. Dependency Inversion Principle (DIP)

  • High-level modules should not depend on low-level modules, but on abstractions.
  • Example: NotificationService depends on MessageSender interface, not directly on EmailSender.