What is the best definition of MVC?

2019-02-02 19:03发布

I have been using Zend Framework in a MVC configuration, read about ruby on rails and plan de check other MVC frameworks in Python(Django?)... i really like the way it isolates some parts of the logic, security and validation. But after just 1 year using it i read an answer here saying almost everyone have wrong definition of MVC and that made me wonder... What is the Right definition of MVC and where could i read about the pattern and standard implementations?

Update: I undertand we all know the BASIC definition (theres a model a controller and a view, the actions on the controller go to the view with some info after making something with the model) but i would love to know what is the definition you THINK everyone KNOWS and why is it wrong( and maybe that will explain to everyone where there could be mistakes, opinions and of course what is your real point of view of this)

7条回答
smile是对你的礼貌
2楼-- · 2019-02-02 19:43

See Chapter 14 of the book: Patterns of Enterprise Application Architecture, by Martin Fowler.

The section on MVC starts with:

"Model View Controller (MVC) is one of the most quoted (and most misquoted) patterns around. It started as a framework developed by Trygve Reenskaug for the Smalltalk platform in the late 1970s. Since then it has played an influential role in most UI frameworks and in the thinking about UI design."

It also says:

"As I think about MVC I see two principal separations: separating the presentation from the model and separating the controller from the view.

...

Of these the separation of presentation and model is one of the most important design principles in software, and the only time you shouldn't follow it is in very simple systems where the model has no real behavior in it anyway. As soon as you get some nonvisual logic you should apply the separation. Unfortunately, a lot of UI frameworks make it difficult, and those that don't are often taught without a separation.

The separation of view and controller is less important, so I'd only recommend doing it when it is really helpful. For rich-client systems, that ends up being hardly ever, although it's common in Web front ends where the controller is separated out. Most of the patterns on Web design here are based on that principle."

查看更多
forever°为你锁心
3楼-- · 2019-02-02 19:44

I trust the MVC definition given here by Martin Fowler. However, you may want to notice the fact that more or less these framework have their own tweak in it. For example a framework like Django is more Model-Template-Controller due to its templating feature.

查看更多
我想做一个坏孩纸
4楼-- · 2019-02-02 19:54

The project is divided into three parts:

  1. model: represented into database.
  2. view: represented into your project’s interface that you could do it using html, javaScript and css.
  3. controller: this is your business logic represented into your functions and it is consider the link between the model and view that represent level of security, too.
查看更多
疯言疯语
5楼-- · 2019-02-02 19:59

The model-view-controller pattern proposes three main components or objects to be used in software development:

  • A Model , which represents the underlying, logical structure of data in a software application and the high-level class associated with it. This object model does not contain any information about the user interface.
  • A View , which is a collection of classes representing the elements in the user interface (all of the things the user can see and respond to on the screen, such as buttons, display boxes, and so forth)
  • A Controller , which represents the classes connecting the model and the view, and is used to communicate between classes in the model and view.
查看更多
来,给爷笑一个
6楼-- · 2019-02-02 20:01

The most major mistake I find with peoples understanding of MVC is that they think the pattern encompasses more than it does. More specifically people often think:

  • Model = DataBase
  • View = HTML
  • Controller = Business Logic and everything else.

This is often the way things work in a smaller application but reality MVC is a way to seperate the Business code from the presentation code. The Model does all the real business work. The views provide the look and feel, and the controller maps one to the other.

查看更多
我欲成王,谁敢阻挡
7楼-- · 2019-02-02 20:01

I believe the same thing. As far as I am concerned anything that manages to separate the concerns of the display, the data/business objects and the control of those (initialisation, responding to user input) gets the benefit that MVC seeks to provide.

The aim is to move these items into re-useable components and be able to swap different implementations in and out and also be able to test the individual pieces in isolation. IMO that's what MVC is all about.

This is a pretty good write up of some of the history and popular implementations of the MVC paradigm. We should add the Model - View - ViewModel pattern that is recommended for WPF in there too.

查看更多
登录 后发表回答