模型视图控制器

发布于 2024-10-02 19:07:06 字数 86 浏览 4 评论 0原文

在我看来,Model 类保存了程序中所有或几乎所有属性的信息......那么它应该包含诸如 getter 和 setter 之类的东西吗?或者我有错误的想法?

It sounds like to me that the Model class holds information about all or nearly all attributes in a program... so should it contain things like getters and setters? Or am I getting the wrong idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

汹涌人海 2024-10-09 19:07:06

getter 和 setter 与模型无关,但充当一个很好的工具,所以我认为你的观点是正确的,但你应该理解 getters 和 setters 与模型原理无关,而是构建模型类的一种方式以适合您的框架。

在MVC中,模型主要是数据,获取和设置是数据管理的重要组成部分,而控制器是这一切中的决策者,用户是否可以拥有这些信息,用户是否可以设置这些信息..

在我看来,MVC 通常是如何工作的:

  • 控制器负责决策,加载什么视图等
  • 模型是视图和数据库/存储之间的层,充当 Getter + Setters
  • 视图是 GUI ,位于用户和模型中间,

因此视图询问控制器是否可以显示某些数据,然后视图将根据登录情况响应 true/false,如果为 true,则视图将向模型询问信息

这就是 MVC 互操作的方式,我可能有点不明白,但或多或​​少这通常是这样的,

希望这张图片能给你比上面更好的描述:
alt text

但关于你的主要问题,我总是将 Getters + Settings 与模型抽象联系起来。

getters and setters are nothing to do with Models, But act as a great tool, So i think your righti n a sence, but you should understand that Getters and Setters having nothing to do with the model principle but are a way to construct your Model Classes to suite your Framework.

With MVC, The Model is mainly Data, getting and setting is vital part of data management, where as Controller is the Decision Maker in all this, Can the user have this information, can the user set the information..

How MVC Usually works in my mind is like so:

  • Controller takes care of the decisions, What views to load, etc
  • Model is the layer between the view and the database / storage, and acts as Getter + Setters
  • The View is the GUI, which is in the middle of the user and the Model

So the View asks the controller if it can show certain data, and then the view will respond true / false depending in the login, if true, the View will then ask the Model for the information

Thats the way interoperate MVC, I may be slightly off but more or less this is usually how it goes

hopefully this image will give you a better description then above:
alt text

But in regards to your primary question, I would always associate Getters + Settings with Model Abstraction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文