您的位置:首页 > 其它

MVC->MVP->MVVM(未完)

2010-08-26 23:46 239 查看
WPF 引入了MVVM模式。

本来就对MVC没有过多了解,这下晕了。

MVC至少还听得多,MVC和MVVM Pattern究竟区别何在?为何MS在推出MVC之后,又推出MVP,再推出现在的MVVM.

????

这个问题得好好想想。

----------------------------------------------------

Compare with MVC &&MVP

http://www.codeproject.com/KB/aspnet/AspNetMvcMvp.aspx

http://www.codeproject.com/KB/architecture/MVC_MVP_MVVM_design.aspx (推荐)

Sometimes you can hear: MVP is similar to MVC.
Then I have to say, yes, but as similar as is the C# similar to Java. You can read Java code very quickly. But if you’ll be sit to the PC with ‘
Eclipse
’ instead of
Visual Studio
, how long will take you to produce ‘Hello World’ application?

First of all we need to correctly ‘localize’ the words in both abbreviations. Look at this two triplets:
Model ViewController
Model ViewPresenter

For this article we will prefer
MVC
syntax and adjust
MVP
.

The first homophone word is Model.

MVC
: Model == Plain container for storing references.
Model
has properties (ValueType, Objects even Collections) but does NOT have methods. This is great advantage of the Model, because whatever information you will need on
View
, put it in the
Model
- May be not so obvious but that's so wonderful place for
AOP
extending...

MVP
: Model == Business. Model is not model as in MVC. It in fact represents the Business Facades or Services (or whatever you named it) which allows you to access objects (Entities, DataTables). This
Model,
bussiness mainly contains methods! Add(), Remove(), Update() ….

The second homophone word is View.

MVC
: View == Viewrepresents
UI
(user interface).
View
takes care for nice layout, smart controls, images, hyper-links. All that stuff is built from information stored in the model.
View
exposes
Controlle
r's
Action
s via 'buttons' and 'links'. When they are clicked –
MVC
directly creates
Controller
and calls its
Action
– and the
View
itself is lost in the past.

MVP
: View == Exposes some properties to its presenter, and as presenter executes all needed calls to the
Model
(Bussiness), assembles itself (
View
) by filling its exposed properties. The user’s requests are handled by
View
s methods. In these methods the Presenter is asked to communicate with Model and refill Exposed properties.

The third words are finally different not only by meaning but even by name

MVC
: Controller == User requests are primarily routed to the Controller’s Actions. Viewat this moment only gathers the user inputs, which are transferred into Model. Controller then calls Business to ‘Get’, ‘Update’, ‘Delete’ etc. and refills the Model. Next the Viewrenders the Model’s content.

MVP
: Presenter == Viewcreates and asks presenter to get or set data from Model-Business. After Presenter fills all exposed View’s properties, the execution continues on Viewside.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: