English 中文(简体)
“控制器”和“控制器”之间的循环依赖
原标题:Circular dependency between "controller" and "gui"

I am writing a complex GUI in Java with many components on several screens working on top of and interacting with a shared piece of logic and model. Clearly there are some circular dependencies between the "gui" and "controller/logic": User actions in GUI are forwarded to controller, which performs some task and then needs to reflect those changes in all GUIs. Something may happen in background that makes controller push updates to GUIs. And so on.

现在,我要谈谈我的问题。 名单或观察员模式在推动对全球倡议进行更新方面发挥着重要作用。 能否使我的全球倡议直接取决于具体的控制阶层? 为什么? 只有一个这样的控制员(而且总是会这样做)。 有十几个控制员呼吁,政府调查组需要投票和执行行动——我不赞成几个三维的接战接口的想法,这些接口总是只有一种执行,也不是所有行动的一个庞大的接战接口。

最佳回答

Is it OK to make my GUI depend on a concrete controller class directly? Why/why not?

No: 因为

是:判决呼吁。 如果松散的政变肯定不会带来未来利益,而且太昂贵,无法为夫妇辩护。

但确实试图避免。 GUI取决于控制器是有效的设计决定。 但总是取决于抽象,从来不执行。 ......你们知道这一点。 我指的是,如果没有人希望放弃控制器,那么你会利用接口获得任何东西。 除思想和平外,如果知道你写了字塔,则不太编码。 或许更容易测试。

至于如何选择全球倡议与控制者之间的沟通,它是一个 to。 你们可以利用这些事件,但把这些事件连接起来是一种拖.,他们跨越边界。 但是,通过利用你可能感到最容易发生政变的事件。 全球倡议和控制人永远不需要相互处理(行动),除非最初将事件连在一起。 这可能感到.。 或者,你可以使用对接口的通话方法,因为接口可能像一个稍加紧的政变一样,但实际上几乎没有什么区别。 您这样做的任何方式,Xhas to都知道有关Y的事项,供他们交流。

全球倡议与控制者之间的通知关系是oka(抽象)。 多指标类集调查模式有许多不同之处。 我每次都使用它,我把它留给我的需要/情绪。 尽管如此,我确实试图a 避免循环依赖。 我倾向于将受扶养人限制在一个方向。 或根本没有。

例如,在我目前的项目中,控制人员知道这些看法,但这些意见绝对没有认为控制人员撤离。 管制人员对意见活动进行节制,并通过单一国家物体将数据反馈给他们。 国家阶级是唯一的观点。 而控制者所知道的唯一事情是,这种观点的界面和国家物体的类型。 这些内容在外部模块中作了界定,以便可以完全删除观点模块,控制人员仍将汇编,反之亦然。 这是一个非常松散的政变。 几乎没有任何东西(双方都依赖第三个单元)。

有些人以其他方式这样做。

Reasons to avoid concrete dependencies

  • difficult to swap one implementaton for another - dependent will likely need modification or at least recompilation
  • harder to maintain - can t modify components independently of each other
  • harder to test in isolation - need to modify and recompile dependent to swap in a mock implementation of dependency
问题回答

我不是MVC/MVP一切的专家,但这里是我大部分时间。

For simple applications where UI automation and testing is not an issue, I go with the GUI depending on a concrete controller (My view actually instantiates the controller). What I do though is make sure the GUI implements some view interface that the controller takes as a parameter in its constructor. In that way, I don t need to use any event or observer-like behavior: the controller has access to the view interface and the view holds a controller as its member. The problem with this approach in my opinion is that it is not really test friendly. While some may argue that MVP (Model View Presenter) may be based on this approach, I don t like the fact that the controller cannot exist without a GUI object being instantiated. Even if you pass a controller as a parameter of the GUI object in its constructor, I tend to consider it more like a hack. Another issue with that approach is that the GUI actually is not passive enough. I like the logic in my UI to be handled by the controller, not the other way around . But that may just be a personal choice.

如果测试成为一个大问题,我确信,全球倡议甚至不知道控制者,因为控制者是瞬息万象(直接或通过依赖注射)的对象。 http://martinfowler.com/eaaDev/SupervisingPresenter.html” rel=“nofollow”>supervising Controller。 这种做法有助于进行大量测试,因为我实际上能够通过提供假执行《全球倡议》或甚至重新使用我的控制员,以不同的方式执行这一看法,来改变整个国际统一倡议。 在此情况下,国际律师联合会实际上可以提出控制人将处理的事件,但只有控制人才能修改基本模式,或在必要时推动对观点的修改(而不是控制人对数据进行更新的看法)。

Just my 2 cents...





相关问题
XML-RPC Standard and XML Data Type

I was looking at XML-RPC for a project. And correct me if I m wrong, but it seems like XML-RPC has no XML datatype. Are you supposed to pass as a string? or something else? Am I missing something? ...

Is it exists any "rss hosting" with API for creating feeds

I am creating a desktop app that will create some reports. I want to export these reports as RSS or ATOM feeds. I can easily create feeds with Rome lib for Java. But I have no idea how to spread them. ...

Improving Q-Learning

I am currently using Q-Learning to try to teach a bot how to move in a room filled with walls/obstacles. It must start in any place in the room and get to the goal state(this might be, to the tile ...

High-traffic, Highly-secure web API, what language? [closed]

If you were planning on building a high-traffic, very secure site what language would you use? For example, if you were planning on say building an authorize.net-scale site, that had to handle tons ...

Def, Void, Function?

Recently, I ve been learning different programming langages, and come across many different names to initalize a function construct. For instance, ruby and python use the def keyword, and php and ...

热门标签