在Swing应用程序中减少耦合的设计模式 [英] Design patterns to reduce coupling in Swing application

查看:147
本文介绍了在Swing应用程序中减少耦合的设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,我现在正在开发一个Java Swing应用程序,而且我正在寻找一些理由。该应用程序相当小,但我注意到,随着代码基础的增加,我的对象图中有很多耦合。我对Swing来说比较新,但是我已经编程了很长时间才能知道这是怎么回事。



我遇到的最大问题是设置我的事件处理。我的子窗口和对象应如何将事件与我的较高级别的对象进行通信,而不必引用它们?我已经做了相当数量的MVC网页编码。这种模式是否适合Swing?我应该建立自己的控制器吗?我想我正在捕鱼人们发现有用的工作与Swing的模式。



提前感谢您的帮助。

解决方案

最好的方法为了减少GUI中的耦合,我想,是使用事件总线。
有几个现有的实现,包括一些支持Swing的具体。



只是 google for swing event bus ,你会发现。



如果你使用 Guice ,您可能还需要查看 guts-events


Hey all, I'm currently working on a Java Swing application and I was looking for some guidence. The application is fairly small, but I'm noticing that as the code base is growing larger, that I have an awful lot of coupling in my object graph. I'm relatively new to Swing, but I've been programming long enough to know where this is headed.

The biggest problem I'm having is setting up my event handling. How should my child windows and objects be communicating events to my higher level objects without having references to them? I've done a fair amount of MVC web coding. Does this pattern lend itself well to Swing? Should I be building my own controller? I guess I'm just fishing for patterns that people have found useful working with Swing.

Thanks in advance for your help.

解决方案

The best way to reduce coupling in a GUI, I think, is to use an Event Bus. There are several existing implementations out there, including some supporting Swing specifically.

Just google for swing event bus and you'll find.

If you use Guice in your GUI, you may also want to take a look at guts-events.

这篇关于在Swing应用程序中减少耦合的设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆