GEF 真的是一个 MVC 框架吗?
在 http://www.vainolo.com/tutorials/ 的教程中,模型的位置是保存在模型中。我想将所有数据保存到文件中,并希望在加载文件时获得相同的视图。
在寻找这个问题的答案时,我得到了另一个更重要的问题:
GEF真的是一个MVC框架吗?
GEF控制器告诉mvc控制器角色取自EditPart。它创建指定的对象。
关于 示例,控制器保存视图部分,但 mvc 模式告诉,控制器仅对用户交互并告诉视图,它必须更新或者什么。
结论是以下代码是错误的,因为它是 EditPart 的一部分并且发生了变化:
public void refreshVisuals(){
IPersonFigure figure = (IPersonFigure)getFigure();
Person model = (Person)getModel();
figure.setName(model.getName());
figure.setSurname(model.getSurname());
}
关于 wikipedia 该视图在模型上有一个观察者,所以 GEF 的以下句子是错误的,不是吗?
EditPart 将实际模型状态同步到视图并实现观察者。
在MVC模式中,控制器必须监听模型的变化。在 GEF 中,EditPart 是控制器,因此它们必须侦听模型以根据模型的新状态更新视图。
那么什么是正确的呢?
为了防止交叉发布,请查看 http://www.eclipse.org /forums/index.php/m/755178/。
in the tutorials from http://www.vainolo.com/tutorials/ the position of the model is saved in the model. I want to save all data to file and want to get the same view, when I load the file.
Searching for an answer for this question, I got another more important question:
Is the GEF really a MVC framework?
GEF Controllers tells the mvc controller role is taken from the EditPart. It creates the specified objects.
Regarding the examples the controller holds view parts, but the mvc pattern tells, that the controller only reacts on user interaction and tells the view, it has to update or what ever.
Concluding on it the following code is wrong, because it is part of EditPart and it changes:
public void refreshVisuals(){
IPersonFigure figure = (IPersonFigure)getFigure();
Person model = (Person)getModel();
figure.setName(model.getName());
figure.setSurname(model.getSurname());
}
Regarding wikipedia the view has an observer on the model, so the following sentence from GEF is wrong, isn't it?
The EditPart syncs the actual model state to the view and implements the observer.
In the MVC pattern, the controllers must listen to the changes of the model. In GEF, EditParts are the controllers so they must listen to their model to update the view according to the new state of the model.
So what is correct?
To prevent cross-posting have a look on http://www.eclipse.org/forums/index.php/m/755178/.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
维基百科在有关 MVC 的文章开头指出“MVC 有不同的风格(MVC 概述)。有时视图可以直接读取模型并更新自身,有时这是由控制器完成的。MVC
提供的主要概念是将呈现与呈现解耦视图不应该包含任何逻辑,模型的更改是由控制器执行的,并且视图的更改是在模型更改时引起的,但这并不意味着控制器不能是更新视图的人。当模型发生变化时,必须有人这样做,对吗?我个人认为直接从模型读取视图并不是一个好的做法,因为这会使它们过于依赖,并且模型和视图应该完全分离。当您必须在模型中进行更改时(例如更改字段)从真实到被计算) - 你不必改变你的视图(但你可能必须改变你的控制器,但这通常更容易)。
希望这能为您解决问题。
The wikipedia states a the start of the article on MVC that " MVC comes in different flavors (MVC overview). Sometimes the view can read the model directly and update itself, sometimes this is done by the controller.
The primary concept that MVC provides is decoupling the presentation from the view, which should contain no logic. Changes to the model are executed by the controllers, and changes to the view are caused when the model is changed. But this does not mean that the controller can't be the one who updates the view when the model changes. Someone has to do it, right? I personally think that having the view directly read from the model is not a good practice since it makes them too dependent, and that model and view should be completely separated. This is great when you have to make changes in your model (for example a field is changed from being real to being calculated) - you don't have to change your view (but you may have to change your controller, but this is normally easier).
Hope this clears things up for you.