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);
Problem Statement:-
- So my first question is does the
userid
, clientid
, timeout_ms
should be Long
object or just simply long
in ClientInput
class?
- Second question I have is, it might be possible that customer can pass wrong information such as
negative user ids
, negative client id
, negative timeout
value etc etc.. Then where I should do this validation? Should I do this validation check in the constructor of ClientInput
class or at some other place? What's the better way of doing this and how should I do the validation?
question from:
https://stackoverflow.com/questions/21034955/when-to-use-long-vs-long-in-java 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…