SOLID_Principles_in_Java
SOLID_Principles_in_Java
• **Example in Java:**
• ```java
• class Book {
• private String content;
• public String getContent() { return content; }
Open/Closed Principle (OCP)
• Software entities should be open for extension
but closed for modification.
• **Example in Java:**
• ```java
• abstract class Shape {
• abstract double area();
• }
Liskov Substitution Principle (LSP)
• Objects of a superclass should be replaceable
with objects of a subclass without affecting
the correctness of the program.
• **Example in Java:**
• ```java
• class Bird {
• void fly() {}
• }
Interface Segregation Principle
(ISP)
• Clients should not be forced to implement
interfaces they do not use.
• **Example in Java:**
• ```java
• interface Workable {
• void work();
• }
Dependency Inversion Principle
(DIP)
• High-level modules should not depend on low-
level modules. Both should depend on
abstractions.
• **Example in Java:**
• ```java
• interface Keyboard {}