Background:
I have extensive experience in web applications, but I have very little or no experience with RCP. Presently, I am working with Java Swing API. Everything is good. The only problem is, I don't feel very confident about my design.
Question:
In web application when we implement MVC, we forward the request to a View
. The Controller
doesn't care about where to show it. Everything is going to be displayed on a page, typically. But in RCP, we need to know where to show this form/table/etc.. I mean which panel, right or left, up or down. That requires a reference to a container component in which we desire to show the thing. How we should design our code to get that reference?
Take:
I am keeping reference to all first level components in the main class -- that has main()
method. And then wherever I need some component, I am doing something like,
JPanel formPanel = MainApp.getMainPanel().getFormPanel();
..
JPanel treePan开发者_如何学运维el = MainApp.getMainPanel().getTreePanel();
Is it okay?
MVC isn't really as much of a thing in RCP, people talk about it but largely it's bullshit.
For sure having a model of your business objects that's separate and had no dependency on any UI code is important. But the lines between Views and Controllers tend to be more blurred I wouldn't sweat it too much.
User interface elements naturally tend to be organized in a tree like you have, though global variables such as your main panel should be avoided.
Lean heavily on the observer pattern.
A Swing Architecture Overview elaborates on Swing's separable model architecture. I found the concept helpful in understanding commonly used Swing components, as well as popular tools like JFreeChart
.
精彩评论