开发者

Model View Controller vs Model View Presenter [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
开发者_运维百科

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 7 years ago.

Improve this question

What do you say? Any good or bad experience in your projects?


I have some tips for you that come from my experience using each.

MVC - This pattern/architecture is old, tried and tested. Really great for web based projects where the views are separated from the server (and the model).

However, I think there are better patterns when the model is available which can be used instead of MVC.

MVP - Use it when you don't have a datacontext that allows binding (ex, WinForms). Also, if you are not able to use ASP.NET MVC for some reason but can still use ASP, MVP might be an easy migration to help separate you views from your model.

As a final note, I know this wasn't asked but MVVM is probably the best of the bunch. You can use this if you have a datacontext which provides a fully featured method of binding to properties and methods of other classes (ie WPF). MVVM is superior to MVP in that it reduces the amount of code since you no longer need to maintain view interfaces.

My post MVVM vs MVP vs MVC: The differences explained explains this in more detail.


Model–View–Controller (MVC) is a software architecture[1], currently considered as an architectural pattern used in software engineering. The pattern isolates "domain logic" (the application logic for the user) from input and presentation (GUI), permitting independent development, testing and maintenance of each.

http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

Model-view-presenter is a software pattern, considered a derivative of the model-view-controller pattern.

http://en.wikipedia.org/wiki/Model-view-presenter

So,

MVC is a design pattern. A design pattern is a code structure that allows for common coding frameworks to be replicated quickly. You might think of a design pattern as a skeleton or framework on which your application will be built. The most obvious benefit of a MVC framework is that it helps you separate the business logic (database) and the presentation logic (design).

Basically:

  1. Models contain any and all code that relates to your database and other data structures. If you had a table called pages, you'd have a model for it and functions within that for selecting, creating, updating, and deleting records from that table, among other things.

  2. Views contain all your display and UI elements, your JavaScript code, Cascading Style Sheets (CSS), HTML, and even PHP.

  3. Controllers hold it all together. Each function in a controller represents a destination or route. If you had a destination called /about, your controller would have a function called about(). Basically, a controller decides which model and which view to run. It is a contract between views and models.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜