wood burning stoves
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "command pattern use" Watch "command pattern use" New topic

command pattern use

Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 752

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


fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

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

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!!
I agree. Here's the link: http://aspose.com/file-tools
subject: command pattern use
It's not a secret anymore!