4 Replies Latest reply: Nov 12, 2013 4:03 AM by Murray9654 RSS

    what is command design pattern? what is the problem that it solves?


      Hi i have been reading few articles on command design pattern but was unable to understand what it is and what problem does it solve. As far as my understanding goes if there is a pre specified method in an object that could execute and perform the necessary activities then it is called as command design pattern. Why is it named as command design pattern, it is because in a shell we use commands to retrieve output. For example when we type "dir" in dos command prompt it returns the list of files. so here we have to remember a preexisting exe file named "dir" which does something when used. So here like we call it command because when "dir" is passed to the computers it returns something that is expected. may be the computer obeys the command issued and return something back. So like wise if there is a method that is defined as as the command, for example in struts framework the action class must have a method "execute()" which is called by the framework to execute the necessary action mapped to it. So if there is a predefined method like "execute" in struts then the object is said to be followed command design pattern. So what actually does it solve?


      What ever i have written is my understanding from the articles i have read about the design pattern. So kindly correct me if i am wrong. Help me understanding what actual problem does this pattern solves. Thanking you in advance.

        • 1. Re: what is command design pattern? what is the problem that it solves?

          This is really off-topic for these forums. You might do better on StackOverflow.com. I'll just say that although the first Design Patterns book came as a revelation to me, it was more for (a) the nomenclature (decorator, factory, facade, etc) which is still with us and (b) about five of the original patterns, which told me things I didn't already know. I've never used any of the others, including Command, and the whole design patterns thing quickly degenerated into farce with what seemed like a sustained attempt to reduce the whole of computer science to design patterns, which really isn't the point. As an example, there is one in another book called Type Object, which is nothing but 3rd normal form, which can be defined roughly in a couple of sentences. This pattern went on for dozens of pages with a very artificial example. I wrote to the mailing list about it: 'Type Object considered hilarious'. I got a rude reply from the original author, which I guess I expected, but also an incredible response from the list owner, saying I should recast my objections in the form of a design pattern. That lost it for me. True story. Moral: don't take this religion, or any IT religion, too seriously. They come around every 18 months or so with the regularity of the next bit of Moore's Law. I've seen dozens of them come and go since 1971, all with something to say, all 90% nonsense.


          See here for a longer version of this incident.

          • 2. Re: what is command design pattern? what is the problem that it solves?

            Thank you so much EJP. Before (long back when sun forums exist) we used to have a forum for design patterns and modeling issues. May be i am vague. I remember that i had a very long discussion about UML issue on the form. So i have looked for that forum and unable to find it, so posted in general forum. Sorry for this and a huge thank you for answering without getting irritated.


            I have done some ground work to understand this. I have documented my understanding of this design pattern.  The following is the link http://yaragalla.blogspot.in/2013/10/command-design-pattern.html

            I have posted the link thinking that it might help somebody who is having the problem of understanding this design pattern. Nothing much. Thank u so much.