[rules-dev] [solver design] Listeners or bigger interfaces?

Geoffrey De Smet ge0ffrey.spam at gmail.com
Sat Jun 9 08:29:31 EDT 2007


["step" etc is explained in 
http://markproctor.blogspot.com/2007/06/local-search-101.html ]


Currently I have something like this

interface ScoreCalculator {
    double calculateScore(...);
}

This used to be stateless, but now it needs to be statefull,
because some score calculators change the weight of constraints between 
steps.
This also means that some ScoreCalculators need to get notified when a 
step is decided.

So I see 2 ways of implementing this:

1) extend the interface:

interface ScoreCalculator {
    double calculateScore(...);
    void stepTaken(...);
}

2) Start introducing Listeners:

interface StepListener {
    void stepTaken(StepEvent event);
}

if (scoreCalculater instanceof StepListener) {
    stepEventFireThingy.add((StepListener) scoreCalculater);
}

Which one would you prefer?

-- 
With kind regards,
Geoffrey De Smet




More information about the rules-dev mailing list