Dependency injection: Difference between revisions

Content deleted Content added
GreenC bot (talk | contribs)
Reformat 1 archive link. Wayback Medic 2.5 per WP:USURPURL and JUDI batch #20
Tags: Mobile edit Mobile web edit
Line 106:
 
// The dependency is injected through a constructor.
Client(final Service service) {
if (service == null) {
throw new IllegalArgumentException("service must not be null");
Line 123:
 
// The dependency is injected through a setter method.
public void setService(final Service service) {
if (service == null) {
throw new IllegalArgumentException("service must not be null");
Line 150:
 
@Override
public void setService(final Service service) {
if (service == null) {
throw new IllegalArgumentException("service must not be null");
Line 161:
private final Set<ServiceSetter> clients = new HashSet<>();
 
public void inject(final ServiceSetter client) {
this.clients.add(client);
client.setService(new ExampleService());
Line 167:
 
public void switch() {
for (final Client client : this.clients) {
client.setService(new AnotherExampleService());
}