Sign up ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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);
    }
}
share|improve this question

migrated from stackoverflow.com Jun 30 '12 at 2:14

This question came from our site for professional and enthusiast programmers.

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.