mvc首先是哪一部分?
我正在使用 mcv 模式创建一个 Web 应用程序。 我想知道,根据您的经验和该领域的研究,认为从模型、控制器或视图中哪个组件开始更好?
I'm creating a web application using the mcv pattern.
I would like to know, from your experience and from studies in the field, from which component is believed is better to start with, the model the controller or the view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
从视图开始可能会更多地激励您,并且很好,因为它有助于将您自己置于用户的思维框架中(总是一件好事)。
它还将帮助您了解您真正需要模型做什么以及不需要什么。模型的简单性非常有用,使用视图可以帮助您认识到这一点。它还将帮助您关注模型-视图界面,这是非常重要的,也是两者之间交互的主要手段。
也就是说,我实际上经常从 Model 开始,因为我已经可以设想理想的 View,并且很容易过度设计 View。
在模型和视图之间来回迭代效果很好,以免过度设计它们。
控制器的概念被夸大了;控制器是使视图和模型之间的交互尽可能优雅和干净的必要代码。因此,这是我在重构时无意中制作的东西,并且不会开始(或者仅在必要时添加,使其保持非常精简和简单)。
Starting with the View may motivate you more, and is good because it helps put yourself in the mindframe of the user (always a good thing).
It will also help you realize what you really do and don't need for the Model. Simplicity of Model is quite useful, and working with the View helps you realize that. It will also help you focus on the Model-View interface, which is very important and the primary means of interactions between the two.
That said, I actually often start on the Model, because I can already envision the ideal View, and it is very easy to overdesign a View.
Iterating back and forth between Model and View works well, so as to not over-engineer them.
The concept of a Controller is overhyped; a Controller is the necessary code to make interactions between View and Model as elegant and clean as possible. It's thus something I would inadvertently make while refactoring, and would not start with (or only add to as necessary, keeping it very lean and simple).
请记住,如果您首先创建视图,并且您的模型已经创建,那么您将无法从 MVC 工具可以为您提供的任何脚手架中受益。仅此一点就应该激励您首先进行某种基本模型。
我通常首先选择模特,然后我发现我会从那里来回切换。整个过程更加迭代,而不是在第一次尝试时就将模型敲定为“完美”。但是大部分工作都是预先完成的,当视图/控制器在此过程中需要其他东西时,我会根据需要返回进行调整或修改。不过,与任何事情一样,这可能会导致一些范围蔓延,因此请坚定地了解总体目标是什么,并坚持下去并首先完成它。您遇到的任何可能是一个不错的功能,但不在初始范围内,请尽可能详细地写下来。然后,稍后您可以浏览您写下的所有内容并将其用于下一个版本。
Keep in mind that if you do your views first, you won't be able to benefit from any of the scaffolding that the MVC Tooling could do for you if you're Models were already created. This alone should motivate you to do some sort of rudimentary Model first.
I usually opt for Models first, and I find that I switch back and forth from there. The whole thing is much more iterative rather than hammer out the models to be "perfect" on the first try. But the bulk is done up front and I later go back to tweak or modify as needed when additional things are needed by the view/controller along the way. As with anything though, this can lead to some scope creep so keep a firm view of what the overall goal is and stick to that and get it done first. Anything you come across that might be a good feature to add that was not in the initial scope, write it down in detail if you can. Then later on you can go through all of the things that you wrote down and use them for the next version.
根据我的经验,最好从模型开始。
From my experience it is best to start with the model.
我想说首先从模型开始,因为模型几乎定义了您所看到的内容。然后创建控制器并从控制器创建视图。
我想你可以从模型或控制器开始。
I would say start with the model first because the model pretty much defines what is going to be in your view. Then create controllers and create your views from the controllers.
I suppose you could start with either the model or controller.
我在开始项目时大多会考虑我需要哪些元素。
一旦我知道我想要/需要什么,我就会开始设计(静态模板)。
一旦我有了静态模板,我就会知道我需要什么代码。
之后,我将从基本控制器开始,并将其扩展以满足我的需要。当我在控制器上工作并且发现应该放置在模型层中的东西时,我开始对模型层进行编程。
我认为这一切都取决于,但这在大多数情况下对我有用。
只要你把它们分开,我想就没什么问题了。
只是我的两分钱
I mostly start my projects thinking about what elements I would need.
Once I know what I want / need I'll start with the design (the static template(s)).
Once I have a static template I'll mostly know what code I'll need.
After that I'll start with the basic Controller and expand it to my needs. When I'm working on the Controller and I find something which should be placed in the Model layer I start programming the Model layer.
I think it all depends, but this works for me most of the time.
As long as you keep it all separated it's all fine I guess.
Just my two cents