mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-23 10:24:58 +00:00
[refactor] Remove unnecessary declarations in service-locator pattern.
This commit is contained in:
@@ -1,37 +1,37 @@
|
||||
package com.iluwatar;
|
||||
|
||||
/**
|
||||
* This is a single service implementation of a sample service. This is the actual
|
||||
* service that will process the request. The reference for this service is to
|
||||
* This is a single service implementation of a sample service. This is the actual
|
||||
* service that will process the request. The reference for this service is to
|
||||
* be looked upon in the JNDI server that can be set in the web.xml deployment descriptor
|
||||
* @author saifasif
|
||||
*
|
||||
* @author saifasif
|
||||
*/
|
||||
public class ServiceImpl implements Service {
|
||||
|
||||
private String serviceName;
|
||||
private int id;
|
||||
|
||||
public ServiceImpl(String serviceName) {
|
||||
// set the service name
|
||||
this.serviceName = serviceName;
|
||||
|
||||
// Generate a random id to this service object
|
||||
this.id = (int)Math.floor(Math.random()*1000)+1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return serviceName;
|
||||
}
|
||||
private final String serviceName;
|
||||
private final int id;
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
public ServiceImpl(String serviceName) {
|
||||
// set the service name
|
||||
this.serviceName = serviceName;
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
System.out.println("Service " + getName() + " is now executing with id " + getId());
|
||||
}
|
||||
// Generate a random id to this service object
|
||||
this.id = (int) Math.floor(Math.random() * 1000) + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
System.out.println("Service " + getName() + " is now executing with id " + getId());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user