模型视图控制器
在我看来,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
getter 和 setter 与模型无关,但充当一个很好的工具,所以我认为你的观点是正确的,但你应该理解 getters 和 setters 与模型原理无关,而是构建模型类的一种方式以适合您的框架。
在MVC中,模型主要是数据,获取和设置是数据管理的重要组成部分,而控制器是这一切中的决策者,用户是否可以拥有这些信息,用户是否可以设置这些信息..
在我看来,MVC 通常是如何工作的:
因此视图询问控制器是否可以显示某些数据,然后视图将根据登录情况响应 true/false,如果为 true,则视图将向模型询问信息
这就是 MVC 互操作的方式,我可能有点不明白,但或多或少这通常是这样的,
希望这张图片能给你比上面更好的描述:
但关于你的主要问题,我总是将 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:
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:
But in regards to your primary question, I would always associate Getters + Settings with Model Abstraction.