org.lsst.ccs.utilities.dispatch
Interface CommandFor<T>
- All Known Subinterfaces:
- SynchronousCommandFor<T>
public interface CommandFor<T>
This interface defines the behaviour of a class implementing a Command pattern.
Example:
Lets define a class Doer that has a method show(String string, int anInt).
When do we need to send a "command" to such an Object instead of just calling directly this method?
It could be that the code that "relays" this invocation does not know much about the sender , the receiver
and the method itself.
for instance we may want to send a "command" to such an Object through the wire and invoke the method across
the network (without predefined RMI) or we have a generic code that dispatches a call to many receivers.
In programming parlance we are going to "reify" the method call: that is transform it into an Object.
So the object representing this method call and implementing the Command could look like that:
class ShowCommand implements CommandFor , Serializable{
String arg1 ;
int arg2 ;
// constructor and everything
public void invokeOn(Doer someInstance) {
someInstance.show(arg1, arg2)
}
}
Now suppose the receiving code reads the command from a Stream
Doer actor ; // initialized
// then later
ShowCommand command = (ShowCommand) objectStream.readObject() ;
command.invokeOn(actor); // and that's it!
- Author:
- bernard Amade
- See Also:
SynchronousCommandFor,
SynchronousCommandDispatcher,
ParallelCommandDispatcher
invokeOn
void invokeOn(T instance)
Copyright © 2013 LSST. All Rights Reserved.