I have two choices to create the "ExpectedHeader", through a factory or via the strategy pattern. Maybe I should add, that a strategy-object already exists (used to customize the ExpectedModel to the TestParameters). I only would have to extend by the method #createExpectedHeader. Is there any obvious advantage of one over the other?
1. Through a factory:
public class ModelBuilder {
//uses factory
ExpectedHeaderFactory factory;
public ExpectedModel deriveExpectedModel(TestParameters testParams) {
ExpectedHeader expectedHeader = factory.createExpectedHeader(testParams);
return ExpectedModel.builder()
.setExpectedHeader(expectedHeader)
.build();
}
}
2. through a strategy pattern:
public class ModelBuilder {
//uses injected strategy
IStrategy strategy;
public ExpectedModel deriveExpectedModel(TestParameters testParams) {
ExpectedHeader expectedHeader = strategy.createExpectedHeader();
return ExpectedModel.builder()
.setExpectedHeader(expectedHeader)
.build();
}
}
The strategy interface (the first two methods are already used in other methods of the ModelBuilder)
public Interface IStrategy {
public modifyText();
public isRelevant();
public createExpectedHeader();
}