Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

command pattern use

 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am trying to understand the command pattern. How you would describe it and when you would use it?

Thanks

 
fred rosenberger
lowercase baba
Bartender
Posts: 12203
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you find when you researched it? What did you read that didn't make sense?

If nothing else, you could always start here.
 
Debal Guha
Greenhorn
Posts: 9
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to describe it as executing one or more command over a receiver by an invoker on request of a client.

Giving an example, I had a complex data model/structure which was represented through an Eclipse RCP front end visually. Clearly there were two modules involved, 1. The GUI representing the data 2. The data itself within some data structure comprising Graphs and B-Trees. On user intervention the model has to change and to be persisted. Moreover there could be different type of user actions possible like sorting in ascending/descending order, add/remove some nodes etc. It was possible to directly modify the data structure through GUI code, but that would unnecessarily clutter the module and separation of concern would not have been achieved.

Hence came commands. GUI buttons acted as clients creating concrete commands, a command invoker class who logs as well as execute the commands and the data structure/model acted as a receiver who were supposed to change differently for different commands.

Hope this example helps you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic