0% found this document useful (0 votes)
461 views

Solid Principle in Java

The document discusses the 5 SOLID principles in Java programming: 1) Single Responsibility Principle (SRP) states that every class should have a single responsibility. 2) Open-Closed Principle (OCP) specifies that code should be open for extension but closed for modification. 3) Liskov Substitution Principle (LSP) requires that subclasses must be substitutable for their base classes. 4) Interface Segregation Principle (ISP) says that client shouldn't be forced to implement interfaces they don't use. 5) Dependency Inversion Principle (DIP) asserts that high-level modules shouldn't depend on low-level modules and both should depend on abstra

Uploaded by

Ajay
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
461 views

Solid Principle in Java

The document discusses the 5 SOLID principles in Java programming: 1) Single Responsibility Principle (SRP) states that every class should have a single responsibility. 2) Open-Closed Principle (OCP) specifies that code should be open for extension but closed for modification. 3) Liskov Substitution Principle (LSP) requires that subclasses must be substitutable for their base classes. 4) Interface Segregation Principle (ISP) says that client shouldn't be forced to implement interfaces they don't use. 5) Dependency Inversion Principle (DIP) asserts that high-level modules shouldn't depend on low-level modules and both should depend on abstra

Uploaded by

Ajay
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Solid Principle in java : -

there are 5 types of SOLID principle in java

S :- Single Responsibility Principle (SRP)


O :- Open-Closed Principle (OCP)
L :- Liskov Substitution Principle (LSP)
I :- Interface Segregation Principle (ISP)
D :- Dependency Inversion Principle (DIP)

1) Single Responsibility Principle (SRP) :- every Java class must perform a single functionality ex.

public class Student


{
public void addStudent();
{
//functionality of the method
}
}

2)Open-Closed Principle (OCP) :- the module should be open for extension but closed for modification

3)Liskov Substitution Principle (LSP) :- derived classes must be completely substitutable for their base cla
sses. In other words, if class A is a subtype of class B, then we should be able to replace B with A without
interrupting the behavior of the program.

4) Interface Segregation Principle (ISP) :- The principle states that the larger interfaces split into smaller o
nes. Because the implementation classes use only the methods that are required. We should not force th
e client to use the methods that they do not want to use.

Ex .
public interface Conversion
{
public void intToDouble();
public void intToChar();
public void charToString();
}

The above interface has three methods. If we want to use only a method intToChar(), we have no choice t
o implement the single method. To overcome the problem, the principle allows us to split the interface into
three separate ones.

public interface ConvertIntToDouble


{
public void intToDouble();
}
public interface ConvertIntToChar
{
public void intToChar();
}
public interface ConvertCharToString
{
public void charToString();
}

5) Dependency Inversion Principle (DIP) :- The principle states that we must use abstraction (abstract cla
sses and interfaces) instead of concrete implementations.

You might also like