I'm looking for best-practice approach in the following case. I have three Java classes: ManualComponent
, AutomaticComponent
and CustomComponent
, which extend abstract class CalculationComponent
and implement the following CalculableComponent
interface:
public interface CalculableComponent {
void calculate();
}
There's another class which aggregates those CalculationComponent
in ComponentBox
:
public class ComponentBox {
private Set<CalculationComponent> components;
public void calculateAll() {
for (CalculationComponent c : components) {
c.calculate();
}
}
}
Everythig worked perfect till I was asked to change the implementation of calculate()
method in CustomComponent
. Currently, this method needs information from other already-calculated CalculationComponents
(=information from Set<CalculationComponent> components
located in ComponentBox
like this calculate(components);
).
My understanding of GRASP is that ComponentBox
class is now Information Expert, because now it contains all information needed to make final calculation (calculateAll();
).
How should I change my classes in order to get best-practice approach?
Thank You for your help! M.