java code design puzzle for common function result module 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);
    }
}
I'm not sure I understood your question fully, but from what I could understand, you do not need to have both TypeOneResult and TypeTwoResult.  In fact, you probably do not need either of them.  You can use the value of the type member of the CommonResult class to distinguish among the different types.