在以下情况下,我正在寻找最佳实践方法。我有三个 Java 类:和ManualComponent
,它们扩展抽象类并实现以下接口:AutomaticComponent
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。