I am trying to solve a puzzle. I came up with a few classes to represent results. They looked similar, so I defined a common Result
class. But what if I need to define different results according to different functions?
In other words, do I need TypeOneResult
and TypeTwoResult
or only CommonResult
?
If I get rid of the different result classes and rely on CommonResult
, how can I store some specific information about the result?
public class Result {
private String id;
private String data;
public Result(String id, String data) {
super();
this.id = id;
this.data = data;
}
}
class CommonResult extends Result{
private String type;
public CommonResult(String id, String data, String type) {
super(id, data);
this.type = type;
}
}
class TypeOneResult extends CommonResult{
public TypeOneResult(String id, String data, String type) {
super(id, data, type);
}
}
class TypeTwoResult extends CommonResult{
public TypeTwoResult(String id, String data, String type) {
super(id, data, type);
}
}