在哪里可以找到 Ken Auer 推广的 Enabler 模式的更多详细信息?

发布于 2024-07-27 13:50:01 字数 150 浏览 6 评论 0原文

Ken Auer 在他的《极限编程应用》一书中不经意地提到了启动器模式。 Kent Beck 也提到了它(至少在 2004 年 11 月 8 日的一封电子邮件中),但我无法在常用的地方(Google、c2.com 上的 wiki 等)找到任何详细信息

。我了解更多?

In his book Extreme Programming Applied, Ken Auer casually mentions an Enabler pattern. Kent Beck also mentions it (at the very least in an email dated November 08, 2004), but I haven't been able to find any details in the usual places (Google, the wiki at c2.com, etc.)

Where can I find out more?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尘世孤行 2024-08-03 13:50:01

启动者模式实际上只是观察者模式的一种变体。 您在系统的有趣部分设置观察者,创建条件。 然后,启动器可以观察条件并启用/禁用小部件。

例如,当您加载窗口时,您可以创建条件来监视列表或组合框(或列表或组合框下方的模型)是否已选择某些内容等内容。 您可以将其称为“somethingSelectedCondition”。 然后,您将启用器连接到与一个或多个条件相关的小部件(您可以和/或一起使用......尽管通常您只想在实践中将它们放在一起)。

我通常通过一个小部件工厂来实现它们,这样您传入的参数之一是一组命名条件,当与一起使用时,启用/禁用小部件。 例如

widgetFactory.createButton(String buttonLabel, String methodActionName, String[] conditionNames)

conditionNames 将查找某种 HashMap 中可用的条件,创建一个 CompositeCondition(与条件的所有观察到的布尔值进行 AND 运算)并创建一个 Enabler,它侦听 CompositeCondition 并告诉创建的小部件根据基础条件启用/禁用。

这听起来有点复杂,但是一旦创建了底层基础设施,几行代码就会连接您的条件,然后用户界面始终与条件同步。

我认为我从未正式编写过启动器模式,或者我只是向您指出一个 URL。

HTH,

The Enabler pattern is really just a variation of an Observer pattern. You set up observers on interesting parts of a system, creating Conditions. Enablers can then observe the conditions and enable/disable widgets.

E.g. when you load up a Window, you create Conditions that watch stuff like whether a list or combo box (or a model underneath the list or combo-box) has something selected. You can call it something like "somethingSelectedCondition". You then hook up enablers to widgets that are tied to one or more conditions (which you can and/or together... though typically you just want to and them together in practice).

I usually implement them by having a widget factory such that one of the parameters you pass in is an array of named conditions that, when anded together, enable/disable a widget. E.g.

widgetFactory.createButton(String buttonLabel, String methodActionName, String[] conditionNames)

The conditionNames will look up Conditions that are available in a some sort of HashMap, creat a CompositeCondition (which ANDs all of the observed boolean values of the conditions) and creates an Enabler which listens to the CompositeCondition and tells the created widget to enable/disable based on the underlying condition.

It sounds a bit complicated, but once you create the underlying infrastructure, a couple of lines of code wire up your conditions, and then the user interface is always in sync with the conditions.

I don't think I ever officially wrote up the Enabler pattern, or I'd just point you to a URL.

HTH,

Ken

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文