gpt4 book ai didi

design-patterns - Poltergeist 反模式示例

转载 作者:行者123 更新时间:2023-12-01 04:02:20 25 4
gpt4 key购买 nike

我试图了解什么是 Poltergeist 反模式,以及它与 Command 或 Delegate 模式有何不同。
我读了:

http://en.wikipedia.org/wiki/Poltergeist_(computer_science)
http://sourcemaking.com/antipatterns/poltergeists

但是没看懂区别...

所以为了清楚起见,我想看看它的代码示例(我更喜欢 C# 或 Java 语言)。

有人有吗?

最佳答案

维基百科描述了命令模式:

The command pattern is a behavioural design pattern in which an object is used to represent and encapsulate all the information needed to call a method at a later time. One component can send a command to another specific component, with the assumption that when some condition is met, the command will be fired.



这个概念很像函数式编程中的仿函数(仿函数基本上是黑盒中的函数,参数等等)

恶作剧被描述为:

The poltergeist is a short-lived, typically stateless object used to perform initialization or to invoke methods in another class.



命令是通用的,必须能够包含足够的状态以供重用。恶作剧者通常是有特殊目的的,他们的存在只是为了在地下室晃动一些椅子并发出巨大的噪音,然后消失。 Poltergeists 通常用作帮助构建或初始化对象的拐杖,很少用于共享构建后的状态变化。

换句话说,是的,它们有点相似,但 poltergeists 不灵活,代表静态 Action ,命令是通用的,可以重用,并代表可配置的 Action 。

关于design-patterns - Poltergeist 反模式示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12801965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com