I have a library, already provided, which has two Scala classes:
class EvaluationFunction (data:DataHolder) {
def calculate(params:ParamHolder) = {...}
}
And
class Regression {
def train(data:DataHolder) = {
...
val costFunction = new EvaluationFunction(data)
//find params to minimize costFunction.calculate(params)
....
}
}
I want to make my own regression class, which behaves exactly like the original regression, but uses a different evaluation function. However, the only way I can think of to do that would involve extending Regression and overwriting the whole train method. But it contains pretty much all the logic in the Regression class - I may as well write it from scratch!
Is there a better way? For example, somehow tell my extended regression class to invoke another class every time the original invokes EvaluationFunction?