I have a suggestion that is being analyzed in different phases. First, I get some attributes (say, X, Y, Z):
public class AnalyzedSentence {
private String X;
private String Y;
private String Z;
public AnalyzedSentence(String sentence) {
extractX();
extractY();
extractZ();
}
}
Then I use these attributes to further analyze the sentence to get another attribute, say, “XYZ”, and then create the following class:
public class FinalSentence {
private AnalyzedSentence data;
private String XYZ;
public FinalSentence(String XYZ, AnalyzedSentence data) {
this.data = data;
this.XYZ = XYZ;
}
}
The workflow is as follows:
public class SentenceAnalyzer {
public FinalSentence analyze(String sentence) {
AnalyzedSentence as = new AnalyzedSentence(sentence);
String XYZ = SpecialClass.extractXYZ(sentence, as);
return new FinalSentence(XYZ, as);
}
}
Alternatively, I could have only one class containing all the information, filling in the attributes as they are retrieved, which may lead to some null results. It will be like this:
public class Sentence {
private String X;
private String Y;
private String Z;
private String XYZ;
public Sentence(String sentence) {
extractX();
extractY();
extractZ();
}
public String getXYZ() {
}
public void setXYZ(...) {...}
}
My question is: which design is preferable and why? If there is also a better way to accomplish what I'm trying to do here, I would also like to hear that.