Domanda

Many webapp frameworks, e.g. Spring,call themselves MVC frameworks, but how is the distinction done between MVC and three-tier? It seems that some frameworks call themselves MVC frameworks but they are really three-tier frameworks, or how do we properly label which is which?

È stato utile?

Soluzione

3-tier applications are applications which are written in 3 separate layers: the presentation layer, the business logic layer and the data access layer.

MVC is a presentation layer pattern which separates Model (data), View (screen) and Controller (input).

Altri suggerimenti

MVC is a three-layer (as oppossed to three-tier) approach, in which presentation logic, business logic and persistence logic are logically separated to achieve simplicity and low coupling.

Three-tier goes a step beyond because each tier is also put appart in specialized servers ( phisical layer ).

MVC and three-tier archivtecture are not mutually exclusive.

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.

Both frameworks separate presentation logic from Business Logic, however the difference is in how that separation is achieved. With 3 tier I tend to think of the layers sitting on top of each other. With MVC, the components sit side-by-side.

With MVC, the controller is the keystone to the architecture, whilst with n-tier it is the view/UI. With an MVC app you call an Action in the Controller, that may or may not render a view. With a 3-tier app you have to go through the UI.

One of the disadvantages of the n-tier system is that business logic may bleed into the data-layer or into the presentation layer, with MVC, I think, it is much easier to keep proper separation of concerns. That though is my experience and preference.

As others have stated MVC and n-tier are not mutually exclusive. The back-end of most MVC websites I've worked on are n-tier. The controllers call a service, that in turn calls a repository.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
scroll top