Single Responsibility Prensibi Nedir ? (Kod örneğiyle) — SOLİD

Single responsibility prensibi
public class User {
private Long id;
private String name;
private String street;
private String city;
private String username;

//Getters, setters

public void changeAddress(String street,String city) {
//logic
}

public void login(String username) {
//logic
}

public void logout(String username) {
//logic
}
}
  • Burada Adres ile ilgili street ve city gibi veriler direkt olarak User sınıfı içerisinde bulunmalı mı gerçekten ?
public class LoginService{
public void login(String username) {
//log-in logic
}

public void logout(String username) {
//log-out logic
}
}
public class AddressService{   
public void changeAddress(User user) {
//logic
}
}
public class User {

private Long id;
private Address name;

//Getter,setter
}
public class Address {

private String street;
private String city;
private String country;
//Getter,setter
}
public class AddressService{   
public void changeAddress(Address address) {
// Sadece addressle ilgileniyorum ve ondan sorumluyum userdaki değişiklikler beni etkilemez.
//logic
}
}

--

--

Software Engineer @Yemeksepeti • #Java • #Spring Boot • #Kotlin • #Spark • #Microservices • https://gokhana.dev

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gökhan Ayrancıoğlu

Gökhan Ayrancıoğlu

Software Engineer @Yemeksepeti • #Java • #Spring Boot • #Kotlin • #Spark • #Microservices • https://gokhana.dev