Below is my Interface:
public interface IDBClient {
public String read(ClientInput input);
}
This is my implementation of the interface:
public class DatabaseClient implements IDBClient {
@Override
public String read(ClientInput input) {
}
}
Now I have a factory which gets the instance of DatabaseClient
like this:
IDBClient client = DatabaseClientFactory.getInstance();
....
Now I need to make a call to read
method of my DatabaseClient
which accepts the ClientInput
parameter and below is the class for the same. This class was not written by me so that is the reason I am having a question on this and I am pretty much sure this is the wrong way of doing it.
public final class ClientInput {
private Long userid;
private Long clientid;
private Long timeout_ms = 20L;
private boolean debug;
private Map<String, String> parameterMap;
public ClientInput(Long userid, Long clientid, Map<String, String> parameterMap, Long timeout_ms, boolean debug) {
this.userid = userid;
this.clientid = clientid;
this.parameterMap = parameterMap;
this.timeout_ms = timeout_ms;
this.debug = debug;
}
}
So when customer make a call to read
method of DatabaseClient
, they will create the ClientInput
parameter like this and then use the factory to get the Instance of DatabaseClient
and then call the read method accordingly.
Map<String, String> paramMap = new HashMap<String, String>();
paramMap.put("attribute", "segmentation");
ClientInput input = new ClientInput(109739281L, 20L, paramMap, 1000L, true);
IDBClient client = DatabaseClientFactory.getInstance();
client.read(input);
Is this the right way of creating the ClientInput
and then passing it to the read method? If not, then what's the best way of doing it? Where should I be doing validation check to see whether the customer has passed valid user IDs or valid client ID, etc.?