如何在 Java 中正确实现 MVC 模式?

How to implement MVC-Pattern in Java correctly?

假设我们的一侧 classes 仅处理 GUI 内容(例如 Java Swing),而另一侧 classes 用于存储数据。这些数据可以保存在外部数据库的表中,而这些表应该由 Java 类 (Hibernate,JDBC).

创建和操作

因此我们的示例软件如下所示:

我现在的问题是如何实现这两个模块之间的link?我是否应该编写一个实现 class 的接口,其中包含它们之间通信所需的所有方法?

或者用 new 在 gui-classes 中实例化数据-classes 并使用数据的 public 方法是否绝对足够-classes?

这里是 Martin Fowler 的书企业应用程序架构模式

的片段

A key point in this separation is the direction of the dependencies: the presentation depends on the model but the model doesn't depend on the presentation. People programming in the model should be entirely unaware of what presentation is being used, which both simplifies their task and makes it easier to add new presentations later on. It also means that presentation changes can be made freely without altering the model.

所以我认为您应该创建不知道谁将访问它们的业务方法。

另一个class(控制器)知道如何根据从视图接收到的数据调用业务方法。