2

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.

monczek
  • 1,142
  • 2
  • 13
  • 28
  • Information expert is about putting a method in the right class, that is, the one that has the information to fulfill the responsibility. I think your calculate methods are ok, but the problem you are having is one of access to information (it is not accessible because of the abstractions)? Can you provide a concrete case of what is not working? – Fuhrmanator Mar 08 '14 at 23:48

0 Answers0