Wednesday 12 February 2048

Recreational lab: recreate your command pattern

Going on vacation tomorrow so here is a lab:
Let's suppose you have an application where two J.V.M. cooperate across the wire (using some serialization).
Now consider things such as :
interface XY_R<X,Y,R> extends {X, Y => R} , Serializable {}
Some code using this (oos is an ObjectOutputStream and the code is in a static main) :
        XY_R<Double,Double, Double> func = { Double x, Double y => x+y } ;
        oos.writeObject(func);

        Double db = new Double(3.14);
        XY_R<Double,Double, Double> func2 = { Double x, Double y => x+y*db } ;
        oos.writeObject(func2);

  • Experiment with more complex closures (embarking instance data)

  • Rewrite a command pattern with that (so one J.V.M can send a command to be executed by the other J.V.M) .

Have fun !
....
.....
Sad note: though this looks fun, deployment problems are tricky (unless you download dynamically the anonymous inner classes from the JVM which initiates ) ... so it's not such a good idea after all!
....
.....
Plus: since generics are a compile-time thing it does not make much sense here in a dynamic context so better stick to interface MyCommand extends {LocalContext => Result } , Serializable {}

.... I need vacations ....

No comments:

About Me

My photo
to graduate at my architecture's school I wrote a thesis on "fuzzy" methods (that was in 1974). afterwards I turned software engineer (and later to java evangelist) but this just strenghtened my views on methods ... I'll try to share (though it is hard to write precisely on fuzzy topics). ...