|
Lazy Commands
LazyCommands are an extension of ActionCommand that delay initialization until the first time they are invoked. This is particularly useful for commands that may be used infrequently and that have high resource cost.
The LazyCommand class defines two abstract methods, build() and lazyExecute(). The first time the command is executed, build will be called followed by lazyExecute. Subsequent command invocations will only call lazyExecute.
Example
public class MyLazyCommand
extends LazyCommand
{
private BigWidget widget;
public MyLazyCommand()
{
super("my-lazy-command");
}
public void build()
{
// lazily build the widget
widget = new BigWidget();
}
public void lazyExecute()
{
// and now we use it
widget.doSomething();
}
}
|