使用命令模式时的常见错误及如何避免

A. Zarras
{"title":"使用命令模式时的常见错误及如何避免","authors":"A. Zarras","doi":"10.1145/3424771.3424773","DOIUrl":null,"url":null,"abstract":"Command, is a behavioral pattern from the Gang of Four catalog that allows us to structure an application with respect to primitive actions that can be easily managed and executed. The main idea is to decouple the objects that invoke actions from the objects that know how to perform them, by encapsulating everything that is needed for executing the actions in corresponding command objects. The application can comprise different classes of command objects that realize different actions. The different classes of command objects implement the same interface. Therefore, command objects can be passed as parameters to other objects that use them to execute the respective actions, without knowing how this is actually done. This paper revisits the Command pattern, focusing on the configuration of command objects, when the data that are needed for the execution of the actions become available as soon as the actions should be executed. In this case, it is not clear which class is responsible for configuring the command objects and how this should be done. The paper reports common mistakes when dealing with this problem, as anti-patterns, observed during the project of a software engineering course. The observed mistakes invalidate the benefits of the Command pattern because the invoking objects are explicitly or implicitly coupled with the concrete classes of command objects that realize the different actions. The paper further introduces a pattern that deals with the problem.","PeriodicalId":216842,"journal":{"name":"Proceedings of the European Conference on Pattern Languages of Programs 2020","volume":"35 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2020-07-01","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"3","resultStr":"{\"title\":\"Common Mistakes When Using the Command Pattern and How to Avoid Them\",\"authors\":\"A. Zarras\",\"doi\":\"10.1145/3424771.3424773\",\"DOIUrl\":null,\"url\":null,\"abstract\":\"Command, is a behavioral pattern from the Gang of Four catalog that allows us to structure an application with respect to primitive actions that can be easily managed and executed. The main idea is to decouple the objects that invoke actions from the objects that know how to perform them, by encapsulating everything that is needed for executing the actions in corresponding command objects. The application can comprise different classes of command objects that realize different actions. The different classes of command objects implement the same interface. Therefore, command objects can be passed as parameters to other objects that use them to execute the respective actions, without knowing how this is actually done. This paper revisits the Command pattern, focusing on the configuration of command objects, when the data that are needed for the execution of the actions become available as soon as the actions should be executed. In this case, it is not clear which class is responsible for configuring the command objects and how this should be done. The paper reports common mistakes when dealing with this problem, as anti-patterns, observed during the project of a software engineering course. The observed mistakes invalidate the benefits of the Command pattern because the invoking objects are explicitly or implicitly coupled with the concrete classes of command objects that realize the different actions. The paper further introduces a pattern that deals with the problem.\",\"PeriodicalId\":216842,\"journal\":{\"name\":\"Proceedings of the European Conference on Pattern Languages of Programs 2020\",\"volume\":\"35 1\",\"pages\":\"0\"},\"PeriodicalIF\":0.0000,\"publicationDate\":\"2020-07-01\",\"publicationTypes\":\"Journal Article\",\"fieldsOfStudy\":null,\"isOpenAccess\":false,\"openAccessPdf\":\"\",\"citationCount\":\"3\",\"resultStr\":null,\"platform\":\"Semanticscholar\",\"paperid\":null,\"PeriodicalName\":\"Proceedings of the European Conference on Pattern Languages of Programs 2020\",\"FirstCategoryId\":\"1085\",\"ListUrlMain\":\"https://doi.org/10.1145/3424771.3424773\",\"RegionNum\":0,\"RegionCategory\":null,\"ArticlePicture\":[],\"TitleCN\":null,\"AbstractTextCN\":null,\"PMCID\":null,\"EPubDate\":\"\",\"PubModel\":\"\",\"JCR\":\"\",\"JCRName\":\"\",\"Score\":null,\"Total\":0}","platform":"Semanticscholar","paperid":null,"PeriodicalName":"Proceedings of the European Conference on Pattern Languages of Programs 2020","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/3424771.3424773","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 3

摘要

Command是一种来自Gang of Four目录的行为模式,它允许我们根据易于管理和执行的基本操作来构建应用程序。其主要思想是通过将执行动作所需的一切封装在相应的命令对象中,将调用动作的对象与知道如何执行动作的对象解耦。应用程序可以包含实现不同操作的不同类的命令对象。命令对象的不同类实现相同的接口。因此,可以将命令对象作为参数传递给使用它们执行相应操作的其他对象,而不知道实际是如何完成的。本文重新审视了Command模式,重点关注命令对象的配置,当执行操作所需的数据在应该执行操作时变得可用时。在这种情况下,不清楚哪个类负责配置命令对象,以及应该如何配置。本文报告了在处理这个问题时常见的错误,如在软件工程课程的项目中观察到的反模式。观察到的错误使Command模式的优点失效,因为调用对象显式或隐式地与实现不同操作的命令对象的具体类耦合在一起。本文进一步介绍了一种处理该问题的模式。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
Common Mistakes When Using the Command Pattern and How to Avoid Them
Command, is a behavioral pattern from the Gang of Four catalog that allows us to structure an application with respect to primitive actions that can be easily managed and executed. The main idea is to decouple the objects that invoke actions from the objects that know how to perform them, by encapsulating everything that is needed for executing the actions in corresponding command objects. The application can comprise different classes of command objects that realize different actions. The different classes of command objects implement the same interface. Therefore, command objects can be passed as parameters to other objects that use them to execute the respective actions, without knowing how this is actually done. This paper revisits the Command pattern, focusing on the configuration of command objects, when the data that are needed for the execution of the actions become available as soon as the actions should be executed. In this case, it is not clear which class is responsible for configuring the command objects and how this should be done. The paper reports common mistakes when dealing with this problem, as anti-patterns, observed during the project of a software engineering course. The observed mistakes invalidate the benefits of the Command pattern because the invoking objects are explicitly or implicitly coupled with the concrete classes of command objects that realize the different actions. The paper further introduces a pattern that deals with the problem.
求助全文
通过发布文献求助,成功后即可免费获取论文全文。 去求助
来源期刊
自引率
0.00%
发文量
0
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
确定
请完成安全验证×
copy
已复制链接
快去分享给好友吧!
我知道了
右上角分享
点击右上角分享
0
联系我们:info@booksci.cn Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。 Copyright © 2023 布克学术 All rights reserved.
京ICP备2023020795号-1
ghs 京公网安备 11010802042870号
Book学术文献互助
Book学术文献互助群
群 号:604180095
Book学术官方微信