mercredi 26 janvier 2022

How does the client knows the concrete service API in Dependency injection design pattern

I'm trying to understand the technical approach for implementing DI.

this code sample is DI taken from https://en.wikipedia.org/wiki/Dependency_injection- the injector is the c'tor:

// Constructor
Client(Service service, Service otherService) {
    if (service == null) {
        throw new InvalidParameterException("service must not be null");
    }
    if (otherService == null) {
        throw new InvalidParameterException("otherService must not be null");
    }

    // Save the service references inside this client
    this.service = service;
    this.otherService = otherService;
}

Now, 2 DI principles:

  1. Thanks to the Service interface the client doesn't care who's the concrete service.
  2. The client need to know the concrete service API.

My question: What is the technical way in which the client get to know the API of the injected service?

Aucun commentaire:

Enregistrer un commentaire