Argument InterfaceA turbocharged version of ArgumentObject.
You want to define an abstract numerical model element for passing to sliders, numeric text boxes etc. To start with this looks pretty simple:
interface Numeric{
String title();
double value();
void setValue(double value);
double minimum();
double maximum();
}
You also need a callback to do stuff when the value changes:
class _AbstractNumeric implements Numeric{
_AbstractNumeric(String Title,double min,double max,double value){...
String title(){...}
double value(){...}
double minimum(){...}
double maximum(){...}
void setValue(double value){
...//range checking etc
valueChanged();
}
abstract void valueChanged();
}
Then things start to get complicated. You have to decide how to handle
The answer is to add helper interfaces to the original:
interface Numeric{
interface Constraints {
double minimum();//Can now vary dynamically
double maximum();
double increment(int step);//Constrain, define nudge values etc
//Handle range errors, force values etc
double validValue(double proposed,double current);
String[]nudgeTitles()//eg "Up","Down"
...//any other features required
}
interface Coupler{//Couples Numeric mechanism to Constraints policy, and both to the client code
void valueChanged(Numeric n);
Constraints constraints(Numeric n);
}
String title();
double value();
void setValue(double value);
Constraints constraints();
}
Now the basic interface is so clean that you can create instances using a single, implementation independent factory method:
final class _FieldFactory{...
Numeric newNumeric(String title,double value,Coupler coupler){...}
}
Not only that, logically linked fields, e.g. coordinates, can call the same coupler when they change. You can have semi-standard _IntegerConstraints, _FractionalConstraints, even _ExponentialConstraints that dynamically adjust the nudge value logarithmically.
To the old computing saw that there is no problem in software that cannot be solved by another indirection, I would add - or interface.
-- DavidWright
EditText of this page
(last edited December 1, 2005)
or FindPage with title or text search