MVC Vs n-tier architecture

回眸只為那壹抹淺笑 提交于 2019-12-17 04:10:57

问题


I was wondering what exactly is the difference between MVC(which is an architectural pattern) and an n-tier architecture for an application. I searched for it but couldn't find a simple explanation. May be I am a bit naive on MVC concepts, so if anyone can explain the difference then it would be great.

cheers


回答1:


N-tier architecture usually has each layer separated by the network. I.E. the presentation layer is on some web servers, then that talks to backend app servers over the network for business logic, then that talks to a database server, again over the network, and maybe the app server also calls out to some remote services (say Authorize.net for payment processing).

MVC is a programming design pattern where different portions of code are responsible for representing the Model, View, and controller in some application. These two things are related because, for instance the Model layer may have an internal implementation that calls a database for storing and retrieving data. The controller may reside on the webserver, and remotely call appservers to retrieve data. MVC abstracts away the details of how the architecture of an app is implemented.

N-tier just refers to the physical structure of an implementation. These two are sometimes confused because an MVC design is often implemented using an N-tier architecture.




回答2:


If a 3-tier design were like this:

Client <-> Middle <-> Data

the MVC patter would be:

     Middle
     ^    |
     |    v
Client <- Data

Meaning that:

  • in the 3-tier equivalent, communication between layers is bi-directional and always passes through the Middle tier
  • in the MVC equivalent the communication is in unidirectional; we could say that each "layer" is updated by the one at the left and, in turn, updates the one at the right –where "left" and "right" are merely illustrative

P.S. Client would be the View and Middle the Controller




回答3:


This is what say about n-tier architecture

At first glance, the three tiers may seem similar to the MVC (Model View Controller) concept; however, topologically they are different. A fundamental rule in a three-tier architecture is the client tier never communicates directly with the data tier; in a three-tier model all communication must pass through the middleware tier. Conceptually the three-tier architecture is linear. However, the MVC architecture is triangular: the View sends updates to the Controller, the Controller updates the Model, and the View gets updated directly from the Model.




回答4:


The only similarity is that the two patterns have three boxes in their diagrams. Fundamentally they are completely different in their uses. If fact, it is not usually a choice between which pattern to use, but both patterns can be use together harmoneously. Here is a good comparison of the two: http://allthingscs.blogspot.com/2011/03/mvc-vs-3-tier-pattern.html




回答5:


A fundamental rule in three-tier architecture is the client tier never communicates directly with the data tier; in a three-tier model all communication must pass through the middleware tier.

It’s liner architecture. This addresses the question of how to pass information between a user and a database. Where as MVC is a triangular architecture: the View sends updates to the Controller, the Controller updates the Model, and the View gets updated directly from the Model. This addresses questions of how a user interface manages the components on the screen.




回答6:


@Cherry Middle ware works more like a request handler or redirector in MVC Pattern.

I would like to explain a bit about MVC, According to me Model View Controller works like this.

  1. Client initiates the session by requesting for any service.
  2. This request is received and handled by Controller (Request handler, redirector etc)
  3. Controller process a basic info on the request and redirect it to the relevant Model which can fill up the data request.
  4. Model fill up the request according to the parameters passed by Controller and send back the results to Controller. (Note: Here i like to clear that data is not directly returned to client in true MVC architecture, rather it fills up and returned to controller.)
  5. Controller than send that data to View(Client).
  6. Client has the requested service in front of him.

That's all about MVC that i know.




回答7:


Give yourself a break. And don't restrict yourself to certain patterns when solving real-world problems. Just remember some general principles, one of which is SEPARATION OF CONCERNS.




回答8:


Besides being linear, another major difference that was not emphasized enough here is that in the N-tier model, N is not necessarily 3-tiers! It is most often implemented as three tiers (presentation, app, data) with the middle layer having two sub-tiers (business logic and data access). Also, the model in MVC can contain both data and business logic for data manipulation, whereas these would be in separate tiers in n-tier.




回答9:


An N-Tier architecture is best defined using a Deployment Diagram.

An MVC architecture is best defined using a Sequence Diagram.

The 2 are not the same and are not related and you can combine the two architectures together. A lot of companies have taken the steps to create N Tier'd architecture for not only deployment and scalability, but for code reuse as well.

For example, your Business Entity objects may need to be consumed by a desktop app, a web service exposed for a client, a web app, or a mobile app. Simply using an MVC approach will not help you reuse anything at all.




回答10:


Conclusion : N-tier is an architecture, MVC a design pattern. They are the same metaphore applied in two different fields.




回答11:


Jerry: Here's a simple example of how the two are related:


Tier 1 - Consists of Models that communicate with Tier 2 through some sort of network service or similar, controllers to handle input validation, calculations and other things relevant for the views. And it contains the views themselves, ofcourse - which can be the GUI in a desktop-app, or the web-interface in a web-app.


Tier 2 - Contains some sort of service or other way of recieving messages from Tier 1. Does not/should not know about Tier 1, so can only answer to calls from above - never ask for things by itself. Also contains all business-logic.


Tier 3 - Contains the domain model, object representation of the database and all logic to communicate and update database-entries.




回答12:


In a three-tier model all communication must pass through the middle tier. Conceptually the three-tier architecture is linear. However, the [model-view-controller] MVC architecture is triangular: the view sends updates to the controller, the controller updates the model, and the view gets updated directly from the model.



来源:https://stackoverflow.com/questions/698220/mvc-vs-n-tier-architecture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!