Sitemap
Javarevisited

A humble place to learn Java and Programming better.

Member-only story

SOLID Principles: OOP Fundamentals

--

Photo by from

You can also read this article on my .

The SOLID principles are five fundamental principles that make software development healthier, more sustainable, and more maintainable. They are a fundamental guide that every developer should follow. These principles can be listed as follows:

  1. Single Responsibility Principle
  2. Open/Closed Principle
  3. Liskov Substitution Principle
  4. Interface Segregation Principle
  5. Dependency Inversion Principle

Let’s examine these principles below with examples.

1.Single Responsibility Principle

Each class and method should have a single responsibility and serve a single purpose.

Let’s say we are handling user registration through an interface, and we direct the request from the interface to the appropriate class and method that create our user.

public class User {
private String username;
private LocalDate birthday;
private int age;
//getters and setters
}
public class UserService {

public User createUser(CreateUserRequest request) {
User newUser = new User()…
Javarevisited
Javarevisited

Published in Javarevisited

A humble place to learn Java and Programming better.

keremmican
keremmican

Responses (1)