简体   繁体   English

我应该将这些字段放在MVC模型中的什么位置?

[英]Where should I put these fields in the MVC model?

Let's say I have three classes: JPSModel , JPSView extends JPanel , and JPSController . 假设我有三个类: JPSModelJPSView extends JPanelJPSController JPSView overrides paintComponent() , which draws an image at a certain zoomFactor at position (renderPositionX, renderPositionY) . JPSView覆盖paintComponent() ,后者在某个zoomFactor位置(renderPositionX, renderPositionY)处绘制图像。

Should zoomFactor , renderPositionX , and renderPositionY , which the user can change, be in JPSView or JPSModel ? 用户可以更改的zoomFactorrenderPositionXrenderPositionY是否应位于JPSViewJPSModel What about methods to calculate zoomFactor , renderPositionX , and renderPositionY like setZoomFit() ? setZoomFit()这样的方法来计算zoomFactorrenderPositionXrenderPositionY方法如何?

They should all be in JPSView since they are not related to "what" (data) is to be displayed; 它们都应该在JPSView因为它们与要显示的“什么”(数据)无关。 they all relate to "where" (positions) and "how" (at what zoom factor) the data is to be displayed. 它们都与要显示数据的“位置”(位置)和“方式”(缩放比例)有关。

Remember Model is persisted and you never save view information along with it unless it's a ViewModel . 记住Model是持久的,除非它是ViewModel ,否则您永远不会将视图信息与之一起保存。 To give you an example, most PDF readers give you an option to reopen the PDF files at the exact same page (as well as the same zoom factor) as it was on the last time you closed it. 举个例子,大多数PDF阅读器为您提供了一个选项,可以在与上次关闭时完全相同的页面(以及相同的缩放倍数)处重新打开PDF文件。 But, that does not mean that it saves the page number and the zoom factor in the PDF itself. 但是,这并不意味着它将页数和缩放系数保存在PDF本身中。

To cater to such situations and if you feel like persisting "last viewed as" related view information a separate JPSViewModel should be created that you should ideally persist in your applications local database and not alongside the file it's processing. 为了适应这种情况,如果您想保留与“上次查看为”相关的视图信息,则应创建一个单独的JPSViewModel ,理想情况下,应将其保留在应用程序本地数据库中,而不要与正在处理的文件一起保留。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM