Dependency Inversion Prensibi Nedir ? (Kod örneğiyle) — SOLID

Dependency Inversion Yazılım Prensibi
public class Email {

public void sendEmail() {
//Send emeail
}
}
public class SMS {
public void sendSMS() {
//Send sms
}
}
public class Notification {

private Email email = new Email();
private SMS sms = new SMS();

public void sender() {

email.sendEmail();
sms.sendSMS();
}

}
public interface Message {
void sendMessage();
}
public class Email implements Message {

@Override
public void sendMessage() {
sendEmail();
}

private void sendEmail() {
//Send email
}
}
public class SMS implements Message {

@Override
public void sendMessage() {
sendSMS();
}

private void sendSMS() {
//Send sms
}
}
public class Notification {

private List<Message> messages;

public Notification(List<Message> messages) {
this.messages = messages;
}

public void sender() {
for (Message message : messages) {
message.sendMessage();
}
}
}

--

--

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