I suggest approach 2 with a factory. The pattern is (maybe) command.
Factory approach
package blammy.result;
public interface Result
{
int calculate();
}
package blammy.result.impl;
public class AResult
implements Result;
{
/*
* Protected constructor to hinder naughty construction.
*/
protected AResult(
int x,
int y,
int a[],
int b[])
{
... blah;
}
public int calculate()
{
int returnValue;
returnValue = ... blah.
return returnValue;
}
}
public class BResult
implements Result;
{
/*
* Protected constructor to hinder naughty construction.
*/
protected BResult(
int x,
int y,
boolean c)
{
... blah;
}
public int calculate()
{
int returnValue;
returnValue = ... blah.
return returnValue;
}
}
public static class ResultFactory
{
public static Result createResult(
int x,
int y,
int a[],
int b[])
{
return new AResult(x, y, a, b);
}
public static Result createResult(
int x,
int y,
boolean c)
{
return new BResult(x, y, c);
)
}
Edit 1
If different calculations require the same parameters, then you should use descriptive name in the factory and in the class name. For example:
public static class ResultFactory
public static Result createBlammy(
int x,
int y,
int a[],
int b[])
{
return new ResultBlammy(x, y, a, b);
}
public static Result createHooty(
int x,
int y,
int a[],
int b[])
{
return new ResultHooty(x, y, a, b);
}