如果你有一系列的双倍,而且每个具体职位都有一个明确的含义,那么你就应该建立一个阶层。
public class MyParamBlob extends ParentParamBlob
{
private double myReadableParameter;
private double anotherParameter;
private double yetOneMore;
// getters and setters as appropriate
}
如果你需要处理现有的<代码>(,从“外面”中可以找到一种构造和(或)一种计数阵列的方法。
public class MyParamBlob
{
...
public MyParamBlob(double[] values)
{
setAll(values);
}
// getters and setters as appropriate
...
public void setAll(double[] values)
{
myReadableParameter = values[0];
anotherParameter = values[1];
// etc.
}
}
Edit - to explain my comment
If the original parent class that this is a subclass of (the reason the double[] exists in the first place) has a getter for the array, that could be overridden in this class, building and returning the array when requested -- e.g.
public double[] getParams()
{
double[] params = new double[4];
params[0] = myReadableParameter;
params[1] = anotherParameter;
// etc.
}
如果阵列为直接 父母类别的实例,如myArray = 母体内,<<>m/code>或 double d2 = 母体内,
, 则 (1) 坏设计和(2) 打电话者可更改在oulInstance.params?