-1

In a swing application, text box 1 depends on combo box 1's selected item. It also depends on Text Box 2's text.Like this, the text box 1 may depend on a variety of components. For all these changes, text box 1's update() method is called (following Observable Pattern rules). How to distinguish as to which component has changed?

4

2 回答 2

1

我不确定我是否理解你。但我认为观察者模式是错误的选择,观察者模式解决了忙等待问题,并通知许多对象主体(可观察者)发生了变化,反之亦然。您可以改变模式规则并让观察者向主题发送他们已更改的消息,但这不再是观察者模式。

注意:在处理设计模式时,请始终查看它们解决了什么问题,因为在许多情况下实现方式非常接近,以至于无法将它们与代码区分开来。

于 2012-05-26T23:33:07.087 回答
0

根据您实现观察者的方式,通常您会提供“发送者”或触发事件的组件。

这样做..虽然您的 Textbox1 订阅了 3 个事件..它可以检查发件人/组件是谁。

于 2012-05-26T23:22:35.970 回答