Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Command pattern
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Overview== The command<ref name="GoF">{{cite book |author=Erich Gamma |author2=Richard Helm |author3=Ralph Johnson |author4=John Vlissides|title=Design Patterns: Elements of Reusable Object-Oriented Software|year=1994|publisher=Addison Wesley|isbn=0-201-63361-2|pages=[https://archive.org/details/designpatternsel00gamm/page/233 233ff]|url-access=registration|url=https://archive.org/details/designpatternsel00gamm/page/233}}</ref> design pattern is one of the twenty-three well-known ''[[Design Patterns|GoF design patterns]]'' that describe how to solve recurring design problems to design flexible and reusable object-oriented software, that is, objects that are easier to implement, change, test, and reuse. Using the command design pattern can solve these problems:<ref>{{cite web |title=The Command design pattern - Problem, Solution, and Applicability |url=http://w3sdesign.com/?gr=b02&ugr=proble |access-date=2017-08-12 |website=w3sDesign.com |archive-date=2020-09-23 |archive-url=https://web.archive.org/web/20200923124858/http://w3sdesign.com/?gr=b02&ugr=proble |url-status=dead }}</ref> * Coupling the invoker of a request to a particular request should be avoided. That is, hard-wired requests should be avoided. * It should be possible to configure an object (that invokes a request) with a request. Implementing (hard-wiring) a request directly into a class is inflexible because it couples the class to a particular request at compile-time, which makes it impossible to specify a request at run-time. Using the command design pattern describes the following solution: * Define separate (command) objects that encapsulate a request. * A class delegates a request to a command object instead of implementing a particular request directly. This enables one to configure a class with a command object that is used to perform a request. The class is no longer coupled to a particular request and has no knowledge (is independent) of how the request is carried out. See also the UML class and sequence diagram below.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)