wood burning stoves 2.0*
The moose likes Java in General and the fly likes command pattern use Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "command pattern use" Watch "command pattern use" New topic
Author

command pattern use

Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 331
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

Joined: Oct 02, 2003
Posts: 11153
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Debal Guha
Greenhorn

Joined: Feb 21, 2013
Posts: 9

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.


You just need to know where to find it!!
 
 
subject: command pattern use
 
Similar Threads
command pattern
Design Patterns with Scala
what design pattern should work here?
which pattern to use
Pattern matching