开发者

Is UI data binding in Java more trouble than it is worth?

开发者 https://www.devze.com 2023-03-02 19:04 出处:网络
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 diff

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 particul开发者_如何学运维ar 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?


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.


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

  • you can test you presentation model (the stuff you bind your components to) without swing, without EDT, just with plain unit tests.
  • you can test you binding with simple test involving only very few Swing Components

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号