R
Richard A. DeVenezia
I am writing some classes for use in an application language that provides
hooks into java objects.
In my app language I have this syntax (I know, not pretty)
j = new ('classname', constructor-arg-1, ..., constructor-arg-N);
j.call{Type}Method ('methodname', method-arg-1, ... methord-arg-N,
result-var);
The args can only be double or String. The {Type} is any numeric primitive
or String. If numeric the return is cast to double.
I am developing classes R and A.
R is runnable.
A is an adapter. A will have to do things the app language can't (because
the app language can not receive an object in return, only Strings and
numbers).
A will manage a pool of threads running R.
i.e. (I know lots of possible problems here)
static private maxCount = 5;
static private count = -1;
static private Thread[] rthreads = new Thread(maxcount);
static private R[] rs = new Thread(maxcount);
void startR () {
count++;
rthreads[count] = new Thread (rs[count] = new R(count)); // let R know
which one it is
rthreads[count].start();
return count;
}
Suppose R has
private double valueX;
public double getValueX() { return this.valueX; }
void setValueX ( int valueX ) { this.valueX=valueX; }
Now, I could have lots of A methods to gain access to a specific R
void setCounter (double index, double valueX) {
rs[index].setValueX (valueX);
}
I would prefer instead to be able to access the R class directly from my app
language, so that I could more simply do:
ja = new ('A');
ja.callIntMethod ('startR', index);
j = new ('R', index);
j.callVoidMethod ('setValueX', 3.141926);
and avoid multiple indirection/dispatch
So I want this weird thing to happen
r1 = new R(1);
r2 = new R(1);
// r1 and r2 should reference the same object
I am hoping that R's constructor can replace what new() wants to return with
R corresponding to A.getR(index)
public class R implements Runnable {
R (double index) {
// somehow cause new to 'return' A.getR(index)
}
....
}
Is there a pattern name for any of this ?
I've heard of factory, but haven't done any reading about that yet.
hooks into java objects.
In my app language I have this syntax (I know, not pretty)
j = new ('classname', constructor-arg-1, ..., constructor-arg-N);
j.call{Type}Method ('methodname', method-arg-1, ... methord-arg-N,
result-var);
The args can only be double or String. The {Type} is any numeric primitive
or String. If numeric the return is cast to double.
I am developing classes R and A.
R is runnable.
A is an adapter. A will have to do things the app language can't (because
the app language can not receive an object in return, only Strings and
numbers).
A will manage a pool of threads running R.
i.e. (I know lots of possible problems here)
static private maxCount = 5;
static private count = -1;
static private Thread[] rthreads = new Thread(maxcount);
static private R[] rs = new Thread(maxcount);
void startR () {
count++;
rthreads[count] = new Thread (rs[count] = new R(count)); // let R know
which one it is
rthreads[count].start();
return count;
}
Suppose R has
private double valueX;
public double getValueX() { return this.valueX; }
void setValueX ( int valueX ) { this.valueX=valueX; }
Now, I could have lots of A methods to gain access to a specific R
void setCounter (double index, double valueX) {
rs[index].setValueX (valueX);
}
I would prefer instead to be able to access the R class directly from my app
language, so that I could more simply do:
ja = new ('A');
ja.callIntMethod ('startR', index);
j = new ('R', index);
j.callVoidMethod ('setValueX', 3.141926);
and avoid multiple indirection/dispatch
So I want this weird thing to happen
r1 = new R(1);
r2 = new R(1);
// r1 and r2 should reference the same object
I am hoping that R's constructor can replace what new() wants to return with
R corresponding to A.getR(index)
public class R implements Runnable {
R (double index) {
// somehow cause new to 'return' A.getR(index)
}
....
}
Is there a pattern name for any of this ?
I've heard of factory, but haven't done any reading about that yet.