Originally did not want to jump out of the big head garlic, but recently found in the garden on the MVC article and discussion of the wind more and more fierce, which has
Some of my friends ' views are not what I admire and recommend, but I have also been busy doing the MVC "literacy work" for my colleagues in the company.
So we collected a number of people in the process of exposure to MVC often appeared to do a little explanation, I hope to communicate with you more,
Oh.
Of course, some of the problems of the architecture pattern itself will be introduced in the following content, but also if you have any
Different points of view, welcome to shoot bricks (as long as not face on the line, hehe).
I. Who made the MVC ?
Model-View-Controller (MVC) is a software invented by Xerox PARC in the 80 's for programming language Smalltalk-80
The design pattern has been widely used so far. In recent years, it has been recommended as a design model for the Sun's Java EE platform, and has received more and more
Welcome to developers using ColdFusion and PHP. Model-View-controller mode is a useful toolbox that has a lot of
Benefits, but there are some drawbacks.
two. is MVC suitable for large-project development
The MVC framework is certainly suitable for big project development, but it doesn't mean that with the MVC framework we can develop large projects that sound
Some around, in fact, is very simple, the reason is that people (developers). If you are an in-depth study of the MVC Framework's design philosophy
, then you will have to consider some of the issues whenever and wherever you use the MVC framework for Product and project development:
1. Low coupling (emphasizing the separation of the view layer and the business layer)
2. Testability (this is very important)
3. High reusability and applicability
4. Beneficial to software engineering management and so on.
Here I appreciate Lao Zhao's scholarly attitude, because in his articles and code in the anytime and anywhere are thinking, especially its
testability, Unit testing (not what TDD is here), makes me feel like I'm connected. Because these problems are
is to do medium-sized or even large-scale projects to think seriously, not to say that Microsoft gave the example is our only criterion, there must be
Right is also wrong, I believe in the face of MVC, domestic and even Microsoft's internal cattle are not many.
Having said this, you can realize that if you do not understand the figure below and the "so-called advantages of MVC
To the "know, and the first to get MVC to develop large projects, I think not only can not play the ASP. NET MVC Framework Estimates
The constraints, configuration, and functionality of the inside, the final feeling is not as good as the direct use of ASP. WebForm Development
Come straight, don't you? In this situation, I think not only can not use MVC for large-scale development, even small and medium-sized enterprises should
Can not be used to cope with.
three. Can I use the MVC architecture for WebForm development?
I personally do not appreciate the idea that someone in the garden is trying to use the ASP. NET MVC framework for the development of WebForm methods
, which is like using the same "weird" SQL statements in a project that uses LINQ, which in the overall style of the code makes people
Confusing, isn't it? Of course, Lao Zhao also mentions in his video lessons the use of some MVC features in the WebForm page (for example:
Modelbinder, etc.), but I think Lao Zhao's intention is not to let this hybrid approach to the development of the road, it must be "non-mainstream",
So the weight of the weight or the people to grasp their own.
Four. Traditional three (N)-tier architecture and MVC, and MVC and MVP relationships
The three-tier architecture described in this article refers to the presentation layer (display layer), the business logic layer, and the data Access layer (persistence). If everyone
If we have to "mechanically" the relationship with MVC, then I can only "twist this melon" here, namely:
The ASPX page of the "presentation layer" in the three-tier architecture corresponds to the view in MVC (the inherited class is different)
The Aspx.cs page (class) of the "presentation layer" in the three-tier architecture corresponds to the controller in MVC, which is not difficult to understand.
The redirect that we've written before, of course, is jumping some link pages in itself, and the controller in MVC is going to be more cool,
It controls and displays a view of the output. That is, the effect is to control the business process and display information, but to achieve
means different.
The business logic layer and data access layer in the three-tier architecture correspond to the model in MVC (the view and controller have found the "husband's",
The rest of the model can only be the business layer and the data Access layer, hehe). But in fact, some of Microsoft's MVC sample projects
The problem is not so simple to understand, as I thought about two MVC examples before me (Mvcstore and oxite) have elaborated
, I will not say more.
Actually understand this relationship, you can try to move the previous three layer structure into the MVC framework, of course, in this process certainly
There are problems like this or that, but the principle is to put the advantages of MVC to the extreme, otherwise it is better not to do.
Speaking of which, in fact, as early as n years ago, someone proposed to use the Frontcontroller (Front controller) to implement the HTTP page, please
(including the presentation of data), it is plain to use HttpHandler for page request processing and data binding,
Instead of completely "counting on" plain page access redirects. The purpose of doing this, as far as I am concerned, with the controller in routing
The starting point of the action is consistent, but the routing implementation is more elegant and lower.
Having finished the three-tier architecture and looking at MVC and MVP, it's important to take a look at this picture before:
After reading the above figure, we will find that the biggest difference between MVP and MVC is "model and view layer between the bottom should not
Communication (even two-way communication). I think this is also the battlefield that the experts who are doing these two aspects of research are arguing with each other now. Must each
There are advantages and costs to be paid for the benefits. At least presenter in MVP mode should have "absolute power". Without it,
Model and view are two islands, although each has its own site (fully decoupled), but will not bring any useful value to the enterprise.
So I have a metaphor here to describe the MVP:
Presenter----is a very powerful woman, even "with what posture", it has to tube.
Of course day million worry more will let oneself want to do more and more, finally it is faced with this layer of code increasingly complicated,
And the writing is not very convenient, it is bound to even the event of this kind of chicken feather to calculate the skin to its tube, tired not tired ah. Finally we see
MVP in the view of the real code patronagejob a lot (state-owned workers), no wonder that view as long as the corresponding iview interface to achieve phase
The expected properties and some simple methods are done, and the final call to the view instance under the IView interface is completely given to presenter,
It reminds me of the idea that MVC can support the "Custom template engine, which ultimately controls the use of systems or custom templates by the MVC framework."
Engine) "and usually we often hang on the mouth of the skin function, think of how much there is really so little meaning (on the spiritual level).
Of course, within Microsoft's understanding of the MVP is also different, as mentioned in the supervising controller mode and the above
You see the Passiveview.
Supervising controller mode is actually very close to the MVC diagram, but also provides the presenter and the view between
"Two-way communication." This approach also has a lot of different opinions, at least for those who support "one-way dependence" of the developer is "
Sneer at. "
Speaking of which, I would like to express my point of view, I am inclined to Passiveview, although this mode is somewhat overbearing, but must be
The real decoupling between the model and the view provides the developer with the greatest sense of control and the ability to control the view.
control, but the problem is the amount of code written and the complexity of the implementation.
Five. What should be in the controller and model
Because the logic in view is relatively simple, the consideration of system complexity is largely focused on the model, and the controller
Is the control of the business process, which should keep the "code fresh". Say so, but the actual development of the project is between the two
Can the line be so clear that the answer is "keep it as far as possible". It must be the "feature" of MVC.
In addition, here we recommend a good way to "robustness", with it you can easily find out those system methods
To put in the model, which should be included in the control logic, which I mentioned in an article two years ago, people interested in
Words can look at this link, using [Iconix] method to practice blog Design Four [robustness analysis].
Its core content is as follows:
Entity object: typically from an object in the domain model (that is, the real world), it often corresponds to database tables and files, which store the data required to execute the use case. Some entity objects are "temporary" objects (such as search results) that disappear when the use case ends. boundary Objects (Boundary object): participants use it to interact with the system, which typically includes windows, screens, dialogs, and menus. If you have a GUI prototype, you will know what many of the main boundary objects are. Control object: A boundary object is associated with an entity object (often referred to as a controller because they are usually not real objects), and it contains most of the application logic, which bridges a bridge between the user and the stored data. The control object contains frequently modified business rules and policies. This modification only needs to be done in these objects, without involving the user interface and the database schema. The controller occasionally (within 20% of the time) will also be the "real object" in the design, but for most of the time, the controller is only a placeholder to avoid any functionality and system behavior that you omit from the use case requirements.
The above three objects correspond to model, View, Controller, respectively.
As stated in the article, the method also provides the following benefits:
1. It helps you to ensure that the use case text is correct and does not specify an unreasonable or impossible behavior (based on the set of images to be used ), thus providing a health check. 2. Help ensure that use cases take into account all the necessary branching processes, providing completeness and correctness checks. 3. Allows you to (persist) The discovery of objects, because some objects may be omitted during domain modeling, and these objects are not easily found when plotting the time -sequence diagram, and it is likely that it is not possible to draw a sequence diagram. 4. Bridging the gap between analysis and design to finalize the preliminary design (about the preliminary design review will be presented in the next article).
Six.can MVC and MVP appear in a single sln or even a project
This point I think who said does not count, only the user needs is kingly, the user uses in the current project to implement some specific
function, which is exactly where MVC or MVP comes in, just one word: " use ".
Finally, one more thing to explain:
Business logic is a part of the system architecture that embodies the core value. Its focus is on the development of business rules, business processes
Implementation and other business requirements related to the system design, so that a system, business logic is ubiquitous. On the view is the display
Logic, the controller is the Process Control logic), the model is simply "logical stronghold".
When using the MVC framework we are going to "change" the Business rules (in the controller) and the relatively stable business logic
(located in model), and is implemented in the model layer in an interface way to address changing business needs in the future.
Well, today's content is here first.
Original link: http://www.cnblogs.com/daizhj/archive/2009/04/30/1447035.html
Author: Daizhj, the earthquake-generation army
[Go] from three-tier architecture to MVC,MVP