Example of simple DI

NotifictionService represents a common service interface for sending data to a different system:

public interface NotificationService {    boolean sendNotification(String message, String recipient);}

The previous interface defines a method signature for sendNotification() by passing the message and recipient details and returning the type as Boolean. SMSService.java is a concrete implementation of this interface for sending SMS notifications:

public class SMSService implements NotificationService {  public boolean sendNotification(String message, String recipient) {    // Code for sending SMS    System.out.println("SMS message has been sent to " + recipient);    return true;  }}

The previous class implemented code for sending SMS by ...

Get Java 9 Dependency Injection now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.