Saturday 15 September 2012

Command pattern java API usage -



Command pattern java API usage -

i'm trying memorize design patterns best can.

i understood best way see design patterns beingness used in java api.

can provide me other java api examples of command pattern other classics java swing , runnable interface?

description on wiki here

important points on command pattern

command pattern helps decouple invoker , receiver. receiver 1 knows how perform action. command helps implement phone call in java. helps in terms of extensibility can add together new command without changing existing code. command defines binding between receiver , action. a command should able implement undo , redo operations. restting state of receiver. can done back upwards of receiver.

command pattern in java api

implementations of java.lang.runnable , javax.swing.action follows command design pattern , , @dave newton said they're pretty examples.then don't need find out much improve examples in java api .

example

i have illustration using runnable swing. in code below runnable object (command) send method argument , can invoked @ time.

runnable runnable = new runnable() { @override public void run() { this.label.settext("updated text"); } }; swingutilities.invokelater(runnable);

summary

the command pattern powerful , flexible design idiom, commonly used in graphical user interface design handle events , commands issued user. design patterns intended allow greater modularity when designing programs, reducing dependencies placed on given block of code.

practise exercise

using command pattern , create little app simulates simple calculator, operations such add, subtract , multiply.

java design-patterns command-pattern

No comments:

Post a Comment