2

次のケースでベストプラクティスのアプローチを探しています。ManualComponentAutomaticComponentおよびの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場所にある情報) を必要としています。ComponentBoxcalculate(components);

GRASP についての私の理解では、ComponentBoxクラスはInformation Expertになりました。これは、最終的な計算を行うために必要なすべての情報が含まれているためです ( calculateAll();)。

ベスト プラクティス アプローチを取得するには、どのようにクラスを変更すればよいですか?

ご協力ありがとうございました!M.

4

0 に答える 0