MVC# Overview概述

Abstract: This article gives an overview of MVC# - a Model-View-Presenter framework for .NET platform. It firstly explains the MVP pattern essentials and then walks through the key features of the MVC# framework which help building true MVP-based solutions.

MVC#概述,.Net平台的MVP框架。首先介绍MVP模式的必要性,接着简要介绍MVC#的关键要素,助力基于MVP模式的解决方案构建。

What is Model-View-Presenter? 什么是MVP
    3-tier architecture 三层架构
    MVC and MVP patterns
MVC和MVP
Why using MVC#? 如何使用MVC#
    1. Views and controllers get
connected automatically
视图和控制器自动连接
    2. Multiple GUI platforms
supported
多种GUI平台支持
    3. Platform-independent
navigation to views
平台独立的视图导航
    4. Tasks concept 任务的概念
Conclusion 结论

What is Model-View-Presenter?什么是MVP?

3-tier architecture三层架构

One of the most fundamental approaches in software engineering is the
Layered architecture. It implies dividing a system into several interacting
layers with certain limitations imposed on how layers may interact.s Layered
architecture finds its application in various systems for example net protocols
(TCP/IP layers), operating systems (three layers: core, drivers, applications)
and others.

软件工程中一个最重要的方法就是分层架构。

A particular case of layered architecture is the 3-tier architecture with
its variations: Model-View-Controller and Model-View-Presenter. Before
considering MVP (and MVC) let us discuss the general 3-tier architecture and
its difference to the conventional programming style.

一个特别的架构模式就是三层架构和他的不同表现形式:MVC和MVP.在考虑MVP或者MVC之前我们先讨论普通的三层架构和传统编程形式的区别。

A straightforward (and widely used) approach in designing applications is
the 2-tier architecture. According to it an application consists of a
presentation layer and a domain layer. Domain layer classes represent the
problem domain entities (e.g. customer, order) and are usually bound to some
database access facilities. Presentation classes in 2-tier architecture have
the following responsibilities:

  • receive user input接受用户输入
  • make necessary calls to
    the domain tier 必要的调用
  • decide what to show next
    to the user 确定下面展示给用户什么
  • display output 显示输出

These responsibilities are rather vast and, as a system grows, may result
in a bloated presentation layer. Moreover they logically can be divided into
two groups: actually presentation logic (code for perceiving input and
displaying output) and application logic (communication with the domain tier
and application flow decisions). These responsibilities require different
programming skills and should better be not mixed in a single module/class. A
quite natural solution is to split this too broad presentation layer into two:
presentation and application logic:


3-tier architecture is rather abstract. While it declares an existence of
three layers, it says nothing about classes in these layers and their
interaction. A much more precise form have two 3-tier architecture variations:
Model-View-Controller and Model-View-Presenter. Let us proceed to their
discussion.

MVC and MVP patterns MVC和MVP模式

According to both MVC and MVP the presentation layer consists of view
objects, and application logic consists of controller objects (we will use
"controller" name instead of "presenter" in MVP). For each
view object a corresponding controller exists and vice versa. And although MVC
and MVP are based on a common 3-tier principle: views process only presentation
needs and controllers handle application logic, these patterns have two major
differences:

在MVC和MVP中表现层包括视图对象。应用层包括控制器对象(使用控制器代替表示器)。每个视图对象对应一个控制器。尽管MVC和MVP基于同样的三层准则:视图只负责表现,控制器处理应用逻辑,这两个模式有两个主要的区别:

  1. In MVC controllers
    receive and process user input, but in MVP views receive user input and
    then merely delegate processing to the corresponding controllers. That is
    why MVP pattern better fits modern UI environments (Windows/Web forms)
    where view classes themselves handle user gestures.

在MVC中控制器接收和处理用户输入,在MVP中视图接受用户输入接着委托给相应的控制器处理。这是为什么MVP模式更适合现在的UI环境(Window/Web Forms),视图类自身处理用户的手势。

  1. In MVC controllers affect
    their views by changing the intermediate presentation model, which the
    views are subscribed to (by observer pattern). This makes views pure observers
    without direct access to them. MVP on the other hand violates this
    "pure observer" rule by providing a direct link from a
    controller to its view. This makes MVP more handy as compared to MVC.

在MVC中,控制器影响他们的视图是通过改变视图订阅的中间媒介表现模型来实现的(根据观察者模式)。这使得视图成为纯观察者而不能直接接触控制器。而另一方面,MVP则侵犯了纯观察者通过直接提供控制器的引用。这使得MVP比MVC更具处理性。

备注:PresentationModel代表了presentation(可视化界面,或者成为视图)的状态和行为,并且是完全独立于界面中使用的GUI控件的…… Presentation Model把视图(View)的状态和行为抽取到model类中,仍然属于presentation层。 Presentation Model要与domain层协同,为视图提供接口,来最小化在view中需要做的决定。视图(view)或者把状态存储到Presentation Model中,或者频繁的与Presentation Model同步状态。


The said differences make the MVP pattern more attractive than MVC from
the developer's point of view. And indeed MVP was designed to be an evolution
of MVC and to improve the latter. That is why we often refer to MVP as
"sharp MVC" and therefore the name our MVP framework is MVC#.

所述的不同从观察者的角度使MVP比MVC更具吸引力。事实上MVP被设计来发展MVC。这使我们为啥称MVP为Sharp MVC 的原因,也是我们的MVP框架称为MVC# 的原因。

Why using MVC#?

Now that we are convinced in the usefulness of the MVP pattern we may
start using it in our applications. However it may be not as easy. Maintaining
an additional application logic layer may require considerable efforts. For
example a developer needs to take care of linking between all views and
appropriate controllers,

Fortunately MVC# automates and takes on itself much of the work concerned
with MVP usage. Thus it simplifies and speeds up the development of MVP
applications. Below is the list of MVC# framework features:

1. Views and controllers get connected automatically

Developers do not have to care about associating views with their
controllers. MVC# framework automatically establishes links between views and
corresponding controllers:

开发者不必关心视图和控制器的关联。MVC# 框架自动实现视图和相应的控制器的连接。

publicclass OrderDetailsView

...

privatevoid processOrderButton_Click(object sender, EventArgs e)

{

// No code needed to establish a link to the
controller

(Controller as OrderDetailsController).ProcessOrder();

}

2. Multiple GUI platforms supported

MVC# allows targeting different GUI platforms (Windows, Web, Silverlight,
etc.) Thus the same application can be used with quite different presentation
layers - one for Windows, the other for Silverlight or Web environment, etc.:


3. Platform-independent navigation to views 平台无关导航到视图。

To make application logic fully independent of the presentation layer,
MVC# provides a platform-independent way of navigating to views. Instead
of  activating a Windows form or redirecting to a Web page a developer
should simply call a uniform Navigator.Navigate(...) method:

为了使应用逻辑完全独立于表现层,MVC# 提供了一个平台无关的导航到视图的方法。无论是激活Windows窗体还是导航到WebPage只要通过调用Navigator.Navigate(...)方法。

publicclass OrderDetailsController

...

publicvoid ProcessOrder()

{

// No Response.Redirect(...) or Form.Show()
calls

Task.Navigator.Navigate(OrderSupportTask.ProcessOrder);

}

4. Tasks concept任务的概念

Another useful feature of MVC# framework, although not directly related to
the MVP pattern, is the Task concept. A task unites several views with their
controllers in fulfilling some job. For example a ticket booking task may
consist of two views: one to choose a ticket, the other - to do the payment. In
MVC# all controllers within a task are given a link to the task object.
Generally a task can be expressed as a workflow or a state machine.

另外一个有用的MVC#元素是任务的概念,尽管不是直接关系到MVP模式。一个任务包括多个视图和它们的控制器来完成一些工作。例如购票任务可能包括两个视图,一个是选票,一个是付款。在MVC#,所有的在一个任务中的控制器,同时指向任务对象。一般地,一个任务可以被表述为一个工作流或者状态机。

Conclusion

MVC# framework frees developers from much of extra work required in
construction of Model-View-Presenter applications. It allows creating flexible
MVP-based application with almost no extra cost. For more information on MVC#
including the examples of using it see the project web site.

[MVCSharp]MVC# Overview概述的更多相关文章

  1. ASP.NET MVC Overview

    ASP.NET MVC Overview The Model-View-Controller (MVC) architectural pattern separates an application  ...

  2. 02 入门 - ASP.NET MVC 5 概述

    目录索引:<ASP.NET MVC 5 高级编程>学习笔记 本篇内容: 一.One ASP.NET 二.新的Web项目体验 三.ASP.NET Identity 四.Bootstrap 模 ...

  3. http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application

    The Contoso University sample web application demonstrates how to create ASP.NET MVC 5 applications ...

  4. OAF_架构MVC系列1 - MVC的概述(概念)

     2015-04-03 Created By BaoXinjian

  5. 001.MVC基本概述

    MVC的基本概念 一.NET平台下开发web应用程序的方案(方法) 方案A:ASP.NET webForm1.web窗体:臃肿(胖)性能低 优点:有很多的web控件可以使用,能够方便的和服务端交互(数 ...

  6. MVC思想概述

    一. 传统Model1和Model2 Model1:整个web应用几乎全部用JSP页面组成,JSP页面接收处理客户端请求,对请求处理后直接作出响应.用少量的javaBean来处理数据库链接,数据库访问 ...

  7. MVC 设计模式概述

    (尊重劳动成果,转载请注明出处:http://blog.csdn.net/qq_25827845/article/details/53292312) 1.MVC设计模式: 如图所示,MVC模式(Mod ...

  8. Model View Controller (MVC) Overview

    By Rakesh Chavda on Jul 01, 2015 What is MVC?Model View Controller is a type of user interface archi ...

  9. mvvm模式和mvc模式 概述总结对比

    1.mvc模式简介: MVC的全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,是一种软件设计典范.例如: angular ...

随机推荐

  1. MySQL助理配置

    基本配置 你需要经常察看以下3个配置项.不然,可能很快就会出问题. innodb_buffer_pool_size:这是你安装完InnoDB后第一个应该设置的选项.缓冲池是数据和索引缓存的地方:这个值 ...

  2. python多线程使用

    内容链接: http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/00138683236 ...

  3. linux 常用的基本命令

    $ ls # 查看文件列表 $ ls dir_name | more : 分页查看文件列表 $ ll -h dir_name # 以 KB.MB.GB格式查看文件大小 $ ll -Sh  # --so ...

  4. directX基础学习系列7 网格(自己创建)

    D3DXMesh 以及 D3DXPMesh都是从ID3DXBaseMesh类中集成,mesh基本是对三角单元进行操作 ID3DXBaseMesh主要函数: HRESULT DrawSubset( DW ...

  5. DirectX基础学习系列4 颜色和光照

    4.1颜色表示 RGB颜色:D3DCOLOR  可以用宏D3DCOLOR_ARGB(a,r,g,b)  D3DCOLOR_XRGB(255,r,g,b) 另外一种浮点表示:D3DCOLORVALUE, ...

  6. Andrew Ng机器学习公开课笔记–Reinforcement Learning and Control

    网易公开课,第16课 notes,12 前面的supervised learning,对于一个指定的x可以明确告诉你,正确的y是什么 但某些sequential decision making问题,比 ...

  7. Python中Unicode字符串

    Python中Unicode字符串 字符串还有一个编码问题. 因为计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.最早的计算机在设计时采用8个比特(bit)作为一个字节(byte ...

  8. 【总结】使用jdbc+servlet开发一个bug管理系统的经验总结

    开发背景: 公司目前使用Teambition里面的task作为bug管理系统,既没有bug的当前状态,也不能写上bug的详细复现步骤,被assign了任务(该修复bug或者验证bug是否被修复)也没有 ...

  9. 汇编查看StackFrame栈帧

    INCLUDE Irvine32.inc myProc PROTO, x:DWORD, y:DWORD .data .code main proc mov eax,0EAEAEAEAh mov ebx ...

  10. SQL SERVER中非聚集索引的覆盖,连接,交叉,过滤

    1.覆盖索引:select和where中包含的结果集中应存在“非聚集索引列”,这样就不用查找基表了,索引表即可搞定:   2.索引交叉:索引的交叉可以理解成建立多个非聚集索引之间的join,如表实体一 ...