Talk:Command pattern

message: I'm a little worried that the example code here just isn't helpful.  As written, the extra indirection of objects with an execute() method serves no purpose.  It would be better to have an example that features some sort of queue (or scheduler or whatever you want to call it) so that the asynchronous aspect of the command execution is emphasised, i.e. the command gets run possibly some time after it is invoked, and the invoker might be in a different thread to the receiver.  —Preceding unsigned comment added by 81.105.217.34 (talk) 15:42, 20 April 2010 (UTC)
thread_title:  Is the example helpful? 

message: What is called the sub-pattern consisting of only Command interface and class ConcreteCommand? This is an important pattern in itself, without the
transactional additions, which can effectively replace function objects and allow lambda calculus to be translated to Java code.
88.112.121.61 (talk) 23:29, 9 March 2010 (UTC)
thread_title:  Sub-pattern of Command and ConcreteCommand? 

message: The link to martin's fowler website, which redirect to a description of the UnitOfWork pattern does not seems appropriate. Are you sure that UnitOfWork is connected to the command pattern ? If so, some text should explain the link... —The preceding unsigned comment was added by 195.68.44.148 (talk) 14:31, 26 April 2007 (UTC)
thread_title:  Link to P of EAA : UnitOfWorks 

message: Since the subject is a topic in computer science, the general explanations should not use a specific programming languages (Java, Python, or whatever) but should be written in pseudocode. Actual code examples (in many languages, preferably) can be shown at the end of the article.
Inquam 07:56, 7 November 2007 (UTC)
thread_title:  Programming Code 

message: I added a simple c++ example.  Let me know what you think.--Michael miceli (talk) 22:32, 7 April 2008 (UTC)
replies: text: I realise this is entirely the subject of the argument above, but I'm not sure C++ is optimal for this; there's a lot of stuff that can be difficult to understand in it. Seems as though Python, which would perhaps lead to a terser example, isn't well-loved either. Would re-writing in Java (it's OO and as ubiquitous as they come) make sense? Scala would make this look great but it's not used by anyone :( --zootm (talk) 11:31, 5 June 2008 (UTC)
replies: text:  Look at how byzantine the Java example above is, then ask that question again. COBOL was once ubiquitous, too. 98.31.54.35 (talk) 01:40, 6 July 2008 (UTC)
replies: text:  Super late reply: Given that the comparable C++ example would be only more complex it seems a bad thing to contrast with, though. Java was the suggestion since it seems to be widely used on here, something simpler might be better, but C++ ain't that. --zootm (talk) 12:53, 2 September 2009 (UTC)
replies: text:  I don't see why it is bad to include a C++ example... it might not be simple or explain the pattern easily, but wouldn't it be helpful for people who are wishing to implement this pattern in C++? Crhopkins (talk) 15:49, 5 January 2010 (UTC)
replies: text:  It's a slippery slope. Look at the histories of any of the Design Pattern pages to see these patterns in every language imaginable. See Talk:Design_pattern_(computer_science)#Extraneous_Examples for my thread that lead to massive cleanup. I'm all for having endless examples in everyone's favorite languages somewhere, like Wikibooks, and having these pages link to them, but these Wikipedia pages should get across the idea of the pattern, not be an implementation cookbook. If it helps the explanation to have multiple languages, then by all means, but in general one language is more than enough. Much as I've never actually used Java, I like it for these example because it is widely-used, strongly-typed, and has garbage collection. With a language without strong typing, many design patterns are harder to follow (because no abstract iterface is needed); the raison d'être of some design patterns even depends on abstract interfaces, so while I love Python for algorithm examples (where working Python is almost as easy to follow as pseudocode), Python is often not a good example language for classic OO design patterns.  Similarly, a language without garbage collection (like C++) adds complexity to examples that isn't necessary. While COBOL was once ubiquitous, and while Java will probably never be the dominant language, Java is the most-used language with the features for which the Gang-of-Four Design Patterns were created, not to mention both came out in the same year (1995, fifteen years ago(!); the age of the Pentium Pro). (Similarly, RAII is best exemplified in C++, with its deterministic scope-based destruction.) —Ben FrantzDale (talk) 14:45, 6 January 2010 (UTC)
thread_title:  C++ example 

message: In Command Design Pattern Class Diagram.png's current version, there is a UML comment on the Receiver class that reads: At some time asks to execute the command. Invoker has exactly the same comment. Why should a Receiver execute commands on it self? Thanks, --134.91.225.10 (talk) 12:40, 17 October 2008 (UTC)
replies: text: Problem still exists. The text at the Receiver should be something like "Is sometimes asked to be executed" or "Will be executed some time".  —Preceding unsigned comment added by 141.52.232.84 (talk) 16:23, 23 February 2010 (UTC)
replies: text: Is fixed now. --Abdull (talk) 16:40, 11 March 2013 (UTC)
thread_title:  Image wrong? 

message: I'm not sure I understand the point of the criticism of the switch. The switch is the implementation of the command's invoker. When the article claims the switch itself should not be aware of any lamp details, is it claiming that the invoker shouldn't be aware of any lamp details? Or is it saying that the switch isn't a good example of an invoker, because a good switch class has an additional restriction that an invoker doesn't need? If I'm reading this article, I don't need to know if the switch class is a good way to model a circuit, I need to know what constitutes a good invoker when the command pattern is used. —MiguelM (talk) 22:39, 21 June 2010 (UTC)
thread_title:  Criticism of Switch is ambiguous 

message: The example is from javaworld (http://www.javaworld.com/javatips/jw-javatip68.html). Someone said about that:"Nice article, but violates basic principles of reknown OO expert".
You can read in GoF: "It's easy to add new Commands, because you don't have to change existing classes". In your example you don't have to define the interface Command. Suppose you want to command a 3-state receiver. You have to change the code in PressSwitch and Switch classes. 
Maybe is better to copy from GoF !.
86.107.49.197 (talk) 18:14, 29 December 2010 (UTC)
thread_title:  Bad article ! 

message: storeAndExecute only execute in javascript, it doesn't store...
/* The Invoker function */
var Switch = function(){
    this.storeAndExecute = function(command){
        command.execute();
    }
}
78.153.242.236 (talk) 14:36, 22 February 2013 (UTC)
thread_title:  javascript example 

message: Given that Scala has first class functions, wouldn't one never actually use the command pattern, as it is unecessary?
Perhaps it could be instructive to show how it can be done more simply by just passing a function?  — Preceding unsigned comment added by 2605:A601:41E8:4100:285D:C783:6890:454A (talk) 22:19, 24 February 2017 (UTC)
thread_title:  Does the Scala example make sense? 

message: Explanation talks about an invoker object, yet the diagram doesn't show one.  — Preceding unsigned comment added by 192.155.0.198 (talk) 21:05, 23 March 2017 (UTC)
thread_title:  Diagram Doesn't Match the Explanation 

message: The article has a section headed "Example", which seeks to illustrate working of command pattern by means of an example. Many years ago over the course of time people added versions transcribed in a range of different programming languages. There are many web sites where that kind of thing is encouraged: a single example is given, and people are invited to provide versions in programming languages that they like. Often getting as many different languages as possible is seen as a desirable aim. However, that is neither consistent with the purpose of Wikipedia nor consistent with the purpose of this article. A collection of versions in different languages may be a good way of illustrating the differences among those languages, and how they may differ in their handling of the same concept, but this article is not about differences in how different languages handle concepts. Nor is serving as a repository of lists of examples of programming code in different languages any part of Wikipedia's aim. One example serves the purpose of illustrating the methods involved in implementing command pattern, and illustrating differences in the ways different languages might be used to do so is off topic for this article. There have been attempts to clean this up; one such attempt dates from almost 10 years ago, when  removed most of the transcriptions into different languages, and added comments in the source requesting editors not to add them back. He wrote: "Wikipedia is not a list of examples. Do not add examples from your favorite programming language here; this page exists to explain the design pattern, not to show how it interacts with subtleties of every language under the sun. Feel free to add examples here: http://en.wikibooks.org/wiki/Computer_Science_Design_Patterns/Command". He added that note both at the beginning and at the end of the example, so that it is difficult to imagine anyone trying to add a new example and not seeing it.
Alas, subsequent editors have ignored that very reasonable request from Ben, and strings of examples have again been added. Recently I tried to do a similar clean up. I was editing from my phone, where I find doing the kind of thorough checking of the history of the article that is needed in order to do this properly is fiddly and difficult, so I provisionally removed the lot, intending to do a better job of it once I got a chance to edit on a computer. With hindsight I think that was a mistake; it would have been better to leave things as they were until I could do it properly. An anonymous editor decided to restore the lot. That editor even restored BenFrantzDale's request not to do so, both the copies Ben had put at the beginning and at the end, at the same time as doing exactly what that message asked one not to do.
I propose to revert to a version with just one example, and with Ben's request in place. If anyone has some reason for thinking that having numerous examples in different languages makes such a large contribution to helping readers to understand the concept of command pattern, which is what the article is about, to justify deviating so greatly from the principle that Wikipedia is not a directory or collection of arbitrary lists then I suggest they explain their reason here, and be willing to discuss the issue, rather than once again ignoring the request in the article and just adding them back without providing any justification for doing so. JBW (talk) 20:26, 16 November 2020 (UTC)
thread_title:  Collections of examples in different programming languages