次のケースでベストプラクティスのアプローチを探しています。ManualComponent
、AutomaticComponent
およびの3 つの Java クラスがあります。CustomComponent
これらは、抽象クラスを拡張し、次のインターフェイスCalculationComponent
を実装します。CalculableComponent
public interface CalculableComponent {
void calculate();
}
CalculationComponent
にあるものを集約する別のクラスがありますComponentBox
:
public class ComponentBox {
private Set<CalculationComponent> components;
public void calculateAll() {
for (CalculationComponent c : components) {
c.calculate();
}
}
}
calculate()
のメソッドの実装を変更するように依頼されるまで、すべてが完璧に機能していましたCustomComponent
。現在、このメソッドは、他の計算済みのCalculationComponents
情報 (=このようなSet<CalculationComponent> components
場所にある情報) を必要としています。ComponentBox
calculate(components);
GRASP についての私の理解では、ComponentBox
クラスはInformation Expertになりました。これは、最終的な計算を行うために必要なすべての情報が含まれているためです ( calculateAll();
)。
ベスト プラクティス アプローチを取得するには、どのようにクラスを変更すればよいですか?
ご協力ありがとうございました!M.