Programming ASP.NET MVC-Fundamentals of ASP.NET MVC(二)
2013-05-23 13:54
501 查看
The Model-View-Controller Architecture
The Model-View-Controller pattern is an architectural pattern that encourages strictisolation between the individual parts of an application. This isolation is better known
as separation of concerns, or, in more general terms, “loose coupling.” Virtually all
aspects of MVC—and, consequently, the ASP.NET MVC Framework—are driven by
this goal of keeping disparate parts of an application isolated from each other.
Architecting applications in a loosely coupled manner brings a number of both short-and long-term benefits:
Development
Individual components do not directly depend on other components, which means
that they can be more easily developed in isolation. Components can also be readily
replaced or substituted, preventing complications in one component from affecting
the development of other components with which it may interact.
Testability
Loose coupling of components allows test implementations to stand in for “pro-duction” components. This makes it easier to, say, avoid making calls to a database,
by replacing the component that makes database calls with one that simply returns
static data. The ability for components to be easily swapped with mock represen-tations greatly facilitates the testing process, which can drastically increase the
reliability of the system over time.
Maintenance
Isolated component logic means that changes are typically isolated to a small num-ber of components—often just one. Since the risk of change generally correlates to
the scope of the change, modifying fewer components is a good thing!
The MVC pattern splits an application into three layers: the model, the view, and th
controller (see Figure 1-1). Each of these layers has a very specific job that it is respon
sible for and—most important—is not concerned with how the other layers do thei
jobs.
The Model
The model represents core business logic and data. Models encapsulate the propertiesand behavior of a domain entity and expose properties that describe the entity. For
example, the Auction class represents the concept of an “auction” in the application
and may expose properties such as Title and CurrentBid, as well as exposing behavior
in the form of methods such as Bid().
The View
The view is responsible for transforming a model or models into a visual representation.In web applications, this most often means generating HTML to be rendered in the
user’s browser, although views can manifest in many forms. For instance, the same
model might be visualized in HTML, PDF, XML, or perhaps even in a spreadsheet.
Following separation of concerns, views should concentrate only on displaying data
and should not contain any business logic themselves—the business logic stays in the
model, which should provide the view with everything it needs.
The Controller
The controller, as the name implies, controls the application logic and acts as the co-ordinator between the view and the model. Controllers receive input from users via the
view, then work with the model to perform specific actions, passing the results back to
the view.
相关文章推荐
- mvcframeworkProgramming ASP.NET MVC-Fundamentals of ASP.NET MVC(四)Controller
- Programming ASP.NET MVC-Fundamentals of ASP.NET MVC(四)Routing
- Programming ASP.NET MVC-Fundamentals of ASP.NET MVC(五)Controller
- Programming ASP.NET MVC-Fundamentals of ASP.NET MVC(六)View
- Programming ASP.NET MVC-Fundamentals of ASP.NET MVC(七)Models
- Programming ASP.NET MVC-Fundamentals of ASP.NET MVC(一)
- Programming ASP.NET MVC-Fundamentals of ASP.NET MVC(三)Convention over Configuration
- Programming ASP.NET MVC-Fundamentals of ASP.NET MVC(八)Putting It All Together
- [翻译]ASP.NET MVC 3 开发的20个秘诀(九)[20 Recipes for Programming MVC 3]:对列表进行筛选
- [翻译]ASP.NET MVC 3 开发的20个秘诀(十一)[20 Recipes for Programming MVC 3]:通过表单上传文件
- Four Ways Of Handling Multiple Submit Buttons In ASP.NET MVC
- Dependency Injection and Inversion of Control with ASP.NET MVC
- Front-line of Front-end, Rational Front-end Performance Tuning in ASP.NET MVC, II
- Visual Studio 2015打开ASP.NET MVC的View提示"Object reference not set to an instance of an object"错误的解决方案
- ASP.NET MVC运行出现Uncaught TypeError: Cannot set property __MVC_FormValidation of null的解决方法
- Can we call the Method of a controller from another controller in asp.net MVC?
- Programming asp.net笔记--第三章 Controls: Fundamental Concepts
- [翻译]ASP.NET MVC 3 开发的20个秘诀(四)[20 Recipes for Programming MVC 3]:实现多语言支持
- [翻译]ASP.NET MVC 3 开发的20个秘诀(二十)[20 Recipes for Programming MVC 3]:缓存结果数据加速页面载入
- Using ASP.NET MVC with Different Versions of IIS