Java 中的 UI 数据绑定是否比其价值更麻烦?
我最近花了一些时间学习并尝试使用各种 Java 数据绑定工具,例如 JGoodies、GlazedLists、JSR-295 等。我一直试图解决的问题并不是这些。虽然很困难,但是我为支持绑定过程而必须编写的代码量远远超过了它提供的任何简化。
我发现所提供的工具除了琐碎的组合和扩展之外没有其他用途(GlazedLists 特别提供了一组很棒的工具,但系统太复杂而无法扩展)。
我真的很喜欢数据绑定的想法,但它的现状似乎存在严重缺陷。我错过了什么吗?
I've spent some time recently learning and attempting to use various Java data-binding tools such as JGoodies, GlazedLists, JSR-295, etc. The problems that I've been trying to solve are not that difficult, however the amount of code I've had to write in support of the binding process heavily outweighs any simplifications it provides.
I've found that the tools provided don't lend themselves to anything other than trivial composition and extension (GlazedLists in particular provides a great set of tools, but is far too complicated a system to extend).
I really like the idea of data-binding, however it seems to be deeply flawed as it stands. Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我所有有关桌面模式和数据绑定的演示都包含有关开发人员在自动数据绑定方面面临的问题的强烈警告。我建议考虑使用像 MVP 这样的桌面模式,它非常易于使用并且不需要绑定。
绑定的问题在于许多隐式操作;如果发生意外情况,这些有帮助,但很难理解,并且只有少数开发人员可以调试和解决第三方绑定链中的问题。
但在过去的三年里,我参与的项目中真正遇到问题的程序员越来越少。所以我倾向于说绑定不再是一个大问题了。
All my presentations regarding desktop patterns and data bindings contain a strong warning regarding the problems developers face with automatic data binding. And I suggested to consider using a desktop pattern like MVP that is quite easy to use and does not need a binding.
The problems with binding are the many implicit operations; these help but are difficult to understand if something unexpected happens, and only a few developers can debug and solve problems in a third-party binding chain.
But during that past three years less programmers in the projects I worked in actually faced problems. And so I tend to say that binding is not such a big problem any more.
如果您的应用程序很琐碎,那么您是否进行绑定或是否一一编写侦听器实际上并不重要。
如果您的应用程序在几个人月内取得了进展,那么在事后引入绑定会带来一些痛苦。几乎所有(有用的)技术都是如此。大量的痛苦可能来自于你之前认为理所当然的混乱。
如果正确使用绑定,您可能会获得 gui 和 gui 行为的完全分离。这反过来意味着
如果您尝试在没有绑定框架的情况下达到相同的目标,您最终将编写自己的绑定框架。
恕我直言,Java 世界中的绑定存在一个严重的问题。它迫使您使用 PropertyChangeSupport 编写 getter + setter,这是乏味且容易出错的。我没有看到在 Java 中修复它的现实方法,但其他语言(例如 Scala)在这里提供了有趣的机会。如果您有兴趣,请参阅我的上一篇博客文章: http://blog.schauderhaft.de/2011/05/01/binding-scala-objects-to-swing-components/
If your app is trivial you it really doesn't matter if you do binding or if you write your listeners one by one.
If you app has made progress for some man months, introducing binding after the fact will cause some pain. The same is true for pretty much every (helpful) technology. Large amounts of the pain might come from the mess you took for granted before.
If you use binding correctly you might gain complete separation of gui and gui behavior. This in turn means
If you try to reach the same without a binding framework you'll end up writing your own binding framework.
There is a serious problem though IMHO about binding in the java world. It forces you to write getters + setter with PropertyChangeSupport, which is tedious and error prone. I don't see a realistic way to fix it in Java, but other languages (think Scala) offer interesting oportunities here. See my last blog post if you are interested: http://blog.schauderhaft.de/2011/05/01/binding-scala-objects-to-swing-components/