Layer-3 architecture ing MVC, MVP [simple introduction]

Source: Internet
Author: User

Of course, some questions about this architecture model will also be introduced in the following content. In addition, if you have any questions
If you have different opinions, you are welcome to shoot bricks (as long as you do not face it, haha ).

1. Who proposed MVC?
Model-View-controller (MVC) is a software invented by Xerox PARC for programming language Smalltalk-80 in 1980s.
The design model has been widely used so far. Sun's J2EE platform design model has been recommended in recent years and is receiving more and more
Developers who use ColdFusion and PHP are welcome. Model-View-controller mode is a useful toolbox with many
But it also has some disadvantages.

Ii. Is MVC suitable for development of large projects?
The MVC framework must be suitable for developing large projects, but it does not mean that with the MVC framework, we can develop large projects. It sounds like
The reason for this is that people (developers ). If you have in-depth research on the design concept of the MVC framework
When using the MVC Framework for product and project development, you will have to consider some issues anytime, anywhere:

1. Low coupling (separation of view layer and business layer is emphasized)
2. testability (this is important)
3. High reusability and Applicability
4. Facilitate software engineering management and so on.

Here, I really appreciate Lao Zhao's academic attitude, because he is thinking anytime and anywhere in his articles and code, especially when
Testability, unit testing (not TDD here) thinking, let me look at the feeling of being connected. Because of these problems
It is necessary to think carefully in medium-sized or even large-scale projects. It is by no means the example given by Microsoft is our only criterion and must include
There are also mistakes. I believe that in the face of MVC, there are not many cool people in China or even Microsoft.

After talking about this, you can realize that if you do not understand the figure below and the "Where is the so-called advantage?" of MVC
When I first came up with MVC to develop large-scale projects, I thought not only could I evaluate the Asp.net MVC framework.
On the contrary, it will always be subject to the constraints, configurations, and features in it. In the end, it is better to directly use Asp.net webform for development.
Come directly, isn't it? In this situation, I think not only can I use MVC for large-scale development, but even small and medium-sized enterprises should
You cannot use it.

Iii. Can I use the MVC Architecture for webform development?
Someone in the garden tried to use ASP. net mvc Framework for webform development. I personally do not like this practice.
This is just as "weird" as using SQL statements at the same time in projects using LINQ, which will make people look at the overall style of the Code.
Confused, isn't it? Of course, Lao Zhao also mentioned in his video course that some MVC functions (such:
Modelbinder, etc.), but I think Lao Zhao's intention is by no means to make this hybrid development popular, and it must be "non-mainstream ",
Therefore, we need to be sure whether it is important or not.

4. Traditional three (n) layer architecture and MVC, and the relationship between MVC and MVP
The three-tier architecture mentioned in this Article refers to: presentation layer (display layer), business logic layer, and data access layer (persistence ). If you
If it is necessary to drag it to MVC, I can only "Twist it" here, that is:

The ASPX page of the "presentation layer" in the three-tier architecture corresponds to the view in MVC (different inherited classes)

In the layer-3 architecture, the Aspx. CS page (class) of the "performance Layer" corresponds to the Controller in MVC. It is not difficult to understand this. Let's think about it.
Redirect, which we have previously written, is of course directed to some link pages, and the Controller in MVC is doing better,
It controls and displays a view. The role of this function is to control business processes and display information, but to achieve
Different methods.

In the three-tier architecture, the business logic layer and the data access layer correspond to the Model in MVC (view and controller must have been found "Mother-in-law ",
The remaining model can only be at the business layer and data access layer ). However, in some of Microsoft's MVC sample projects
The problem is not easy to understand. This is explained in my previous thoughts on two MVC examples (mvcstore and oxite ).
Too much.

If you understand this relationship, you can try to migrate the previous three-tier structure to the MVC framework.
But the principle is to take advantage of MVC to the extreme, otherwise it is better not to do so.

Speaking of this, in fact, as early as N years ago, someone proposed to use frontcontroller (front-end Controller) to implement requests for HTTP pages.
To put it bluntly, httphandler is used to process page requests and bind data,
Instead of simply "expecting" normal page access redirection and so on. The purpose of this is to work with the Controller in routing.
It is consistent with the starting point of action, but the routing implementation is more elegant and more underlying.

After talking about the three-tier architecture, let's look at MVC and MVP. In fact, before that, we need to look at this figure:

 

After reading the above figure, you will find that the biggest difference between MVP and MVC is that "the bottom of the model and view layer should not be
Communication (or even two-way communication ,). I think this is also the battlefield where experts who are currently engaged in these two fields are arguing. Must be
There are benefits and the price to be paid for the benefits. At least the presenter in MVP mode must have "absolute power ". Without it,
Model and view are two isolated islands. Although each has its own territory (completely decoupled), they will not bring any useful value to the Enterprise.
So here is a metaphor to describe MVPs:

Presenter-a woman with a strong desire for control, even "in what posture", it has to take care of it.

Of course, if you worry too much, you will have to do more and more things. In the end, it will face the increasing complexity of code at this layer,
And it is not easy to write, so even the events bound to this kind of chicken feathers should be taken care of by it. Finally, we can see
The view in MVP really has a lot of idle code (state-owned enterprise employees). It is no wonder that the view only needs to be implemented under the corresponding iview interface.
The corresponding attributes and some simple methods are finished, and the view instance that finally calls the iview interface is completely handed over to the presenter,
This reminds me of the support of the "Custom template engine" in MVC (the MVC framework is used to control the use of the system or custom templates.
Engine) "as well as the skin-changing function, which is commonly used at ordinary times, it is really interesting to think about it here (on the mental level ).

Of course, Microsoft's internal understanding of MVP is also different, as mentioned in the supervising controller mode and above
Passiveview.
 

The supervising controller mode is actually very similar to the MVC figure, but it provides the presenter and view
". This approach also has many different opinions, at least for developers who support "one-way dependency",
Sneer.

Speaking of this, let me express my point of view. I prefer passiveview. Although this mode is somewhat overbearing, it must be
Real decoupling between the model and view provides developers with the greatest sense of accomplishment in control.
Control, but the problem is the code writing volume and implementation complexity.

5. What should be included in the Controller and model?
Because the logic in the view is relatively simple, the consideration of system complexity should basically be focused on the model, while the Controller
Is the control of business processes, it should be "refreshing code ". That is to say, but in actual project development
Can the line be so clear? The answer is "keep it as secure as possible ". It must be the "characteristic" of MVC.

In addition, we recommend a good method "robustness". With this method, you can easily find out the system methods.
Which of the following methods should be put in the model into the control logic? I mentioned this method in an article two years ago.
Let's take a look at this link and use the [iconix] method to practice blog design 4 [robustness analysis].
Its core content is as follows:

Entity object ):
It is usually an object from the domain model (that is, the real world), which usually corresponds to database tables and files, these data tables
And files to store the data required for executing the use case. Some entity objects are "temporary" objects (such as search results ).
It will disappear.

Boundary object ):
Participants use it to interact with the system, which usually contains windows, screens, dialogs, and menus. If a GUI prototype exists,
You will know what many major boundary objects are.

Control object ):
Associate boundary objects with object objects (usually called controllers because they are not real objects ),
It contains most of the application logic, which builds a bridge between the user and the stored data. Control objects include frequently
Modified business rules and policies. In this way, you only need to modify these objects, instead of involving the user interface and database.
Mode. The Controller occasionally (20% of the time) will also be the "real object" in the design, but most of the time, the Controller only
Is a placeholder used to prevent you from missing any functions and system actions required by the use case.

The above three objects correspond to model, view, and controller respectively.

As mentioned in this Article, this method also provides the following benefits:

1. It helps you ensure the correctness of the use case text and does not specify unreasonable or impossible behavior (based on a set
Health Check.
2. It helps ensure that all necessary branch processes are taken into account in the use case, thus providing integrity and correctness checks.
3. allows you to (continuously) discover objects, because some objects may be missed during Domain Modeling, and these objects are
Sequence diagrams are not easy to be found, and they are likely to make it impossible to draw sequence diagrams.
4. narrow the gap between analysis and design to final the preliminary design (the preliminary design review will be introduced in the next article ).

 

6.Can MVC and MVP appear in an SLN or even a project at the same time?
I don't want anyone to count on this point. Only user requirements are king. Users can implement some specific functions in the current project.
Function, and this function is exactly the use of MVC or MVP, then the word:"Use".

 
At last, I would like to explain one more point:

Business logic is part of the core value of the system architecture. Its focus is mainly on the formulation of business rules and business processes.
Implementation and other system designs related to business needs. Therefore, for a system, business logic is everywhere. View is an explicit
Logic, the controller is the process control logic), and the model is simply a "logical base camp.

When using the MVC framework, we need to set "frequently changing" Business Rules (in the Controller) and relatively stable business logic
(In the model) is separated and implemented using interfaces at the model layer to meet the ever-changing business needs in the future.

Well, today's content will come here first.

Http://www.cnblogs.com/coolbeibei/archive/2009/06/29/1513434.html

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.