Command pattern: Difference between revisions
Add new page |
Category reorg |
||
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
'''Command pattern''' is a basic [[design pattern]] in [[object-oriented programming]] in which an [[object]] is used to [[encapsulation|encapsulate]] data and behavior in order to perform an action or trigger an [[event]] at a later time. The client then executes a command through a common interface that is provided by the parent [[class]]. | '''Command pattern''' is a basic [[design pattern]] in [[object-oriented programming]] in which an [[object (object-oriented programming)|object]] is used to [[encapsulation|encapsulate]] data and behavior in order to perform an action or trigger an [[event]] at a later time. The client then executes a command through a common interface that is provided by the parent [[class (object-oriented programming)|class]]. | ||
This pattern is typically used in message handlers to avoid the need to convert data to/from [[variant]] or [[string]]. It requires the definition of a generic parent class, which defines the interface that must be implemented by its child classes. For every command a new child class is required. Each child class then overrides the execution method of the parent class to implement the specific functionality. | This pattern is typically used in message handlers to avoid the need to convert data to/from [[variant]] or [[string]]. It requires the definition of a generic parent class, which defines the interface that must be implemented by its child classes. For every command a new child class is required. Each child class then overrides the execution method of the parent class to implement the specific functionality. | ||
| Line 17: | Line 17: | ||
[[Category:Object-Oriented Programming]] | [[Category:Object-Oriented Programming]] | ||
[[Category:Object-Oriented Design Pattern]] | [[Category:Object-Oriented Design Pattern]] | ||
Latest revision as of 21:01, 2 June 2020
Command pattern is a basic design pattern in object-oriented programming in which an object is used to encapsulate data and behavior in order to perform an action or trigger an event at a later time. The client then executes a command through a common interface that is provided by the parent class.
This pattern is typically used in message handlers to avoid the need to convert data to/from variant or string. It requires the definition of a generic parent class, which defines the interface that must be implemented by its child classes. For every command a new child class is required. Each child class then overrides the execution method of the parent class to implement the specific functionality.
The command pattern is sometimes combined with the channeling pattern for pre-processing/post-processing around the execution method of child classes.
