MVC vs. 3-tier architecture?

老子叫甜甜 提交于 2019-12-08 22:38:43

问题


What is the basic difference between MVC and 3-tier architecture?


回答1:


3-tier is a Architecture Style and MVC is a Design Pattern.

so is Different in that.

but we could using mvc pattern in 3-tier architecture style.

so:

Presentation Tier: "Controllers and Views" from MVC Pattern.

Business Tier : "Model(Data)" from MVC Pattern.

Data Access Tier : Original Data Access Tier.




回答2:


In larger applications MVC is the presentation tier only of an N-tier architecture. The models views and controllers are only concerned with the presentation, and make use of a middle tier to populate the models with data from the data tier.

MVC can also be used as the entire 3-tier architecture where Views are your presentation, Controllers are your business logic and Models are your data layer (usually generated by a DAL such as Entity Framework).

Ideally though you want your controllers to be skinny and dumb, passing off logic to a 'business component', which would essentially become your middle tier.




回答3:


In the 3-tier architecture, communication between tiers is bi-directional. In the MVC 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.

3-Tier architecture usually deploy as 3 separate processes on 3 separate network nodes. But MVC is designed to deploy as a single process in a single network node. (like a desktop application)

Business tier in 3-tier usually contains different layers implementing famous patterns like business delegate, business façade, business object, service locator, data transfer object, etc. But MVC is a design pattern itself that is used in presentation tier.

The goal of 3-tier is separation of business logic from client and database, so provide multiple client protocols, high scalability, heterogeneous data access, etc. But the main goal of MVC is that implementation changes in one part do not require changes to another.




回答4:


I take a different approach compared to what Michael said in his response.

Controllers are never meant to be your business logic. For me, business logic belongs to the model layer. And though, views (and to some extent controllers) and part of the presentation layer, model is never a part of it in an MVC application. Model should be the heart and soul of an MVC application and that is what Domain Driven Design is all about which can be easily implemented in an MVC application.

Please remember that you don't have to have the model inside the same project (speaking of ASP.NET MVC). It could reside in an entirely different project and it can still act as a model to the application

An MVC application acting as a presentation layer only can work in a huge project with many tiers but it can never act as a presentation only layer in a 3 tier architecture which is what the questioner asked.

So we can say that MVC makes two (third can be the data layer which isn't really part of MVC architecture per se) out of three layers of a 3-tier architecture.

Thanks.




回答5:


There is no relationship between the two. MVC is a presentation layer pattern. The whole Model-View-Controller exists in presentation layer.

  • Model is object holding data (usually just VOs) which are represented by View or, populated from View.

  • Controller is what gets the request (and may populate the model) and calls the service layer. Then gets another (or same) model and sends it back to View.

  • View is what displays model, and provides components to capture user input. (It is usually a template engine in Web Applications, or UI components in a desktop application).

When talking about 3-tier (or n-tier) application we are talking about architecture of the whole application, which consists of Presentation Layer (the whole MVC), the Service Layer (Business classes), and Data Access Layer.

The Service Layer (and all behind that) are hidden behind the Controllers of MVC.




回答6:


What is a 3-tier architecture?

Three-tier (layer) is a client-server architecture in which the user interface, business process (business rules) and data storage and data access are developed and maintained as independent modules or most often on separate platforms. Basically, there are 3 layers, tier 1 (presentation tier, GUI tier), tier 2 (business objects, business logic tier) and tier 3 (data access tier). These tiers can be developed and tested separately.

DAL - Data Access Layer ( it has Connectionstring and Data read & execute process)

BOL - Bussiness Object Layer ( it has Queries )

UI - User Interface ( Forms & Code Behind )

More Details : 3 Tier Archtecture




回答7:


A 3-tier architecture is linear where the client tier never actually communicates with the data tier--all communication passes through the middle tier. MVC on the other hand is more triangular where the view sends updates to the controller and receives updates from the model and the controller updates the model.

(See "Comparison with the MVC architecture" on http://en.wikipedia.org/wiki/3-tier_architecture)




回答8:


IMO there is no direct comparison between 3-Tier architecture and MVC. Both are used in conjuction and hence we tend to see them through the same lense. Conceptually they need not to be used together. I could have 3-Tier architecture that does not use what MVC has to offer.

I am not elaborating the definitions part, but in nutshell:

3-Tier is a software architecture approach, in which the user interface, business process are logic, data tier developed independently, most often on separate platforms.

MVC has evolved from software pattern to architectural pattern over a period of time and is seen in all major frameworks nowadays.




回答9:


Every Application has one are more of following Layers 1)Presentation Layer or UI Layer 2)Business Layer or Business Logic Layer 3)Data Access Layer or Data Layer

3-tier architecture usually has each layer separated by the network. I.E. the presentation layer is on some web servers, then that talks to back-end 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).

some times we requires more layers of the above type and more mechines then it is called as N-tier

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. Model on which model we wanted to build View means UI of the Application Contol Means the logic Which controls the Application

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




回答10:


My experience is that MVC is a just another "fad" term for badly-written 3-tier, where some of the communication jumps around the business layers, and thus the client and/or data layer also has business rules mixed in.

I hate code written like that - The term MVC must have been designed to confuse HR recruiters into thinking older programmers (who know it as "3-tier") are not matched for the job.




回答11:


In MVC : 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

In Three Tier : 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 middle tier

Vikas Joshi Software Engineer




回答12:


  • 3-Tier is linear architecture. (Presentation tier -> Logic tier -> Data tier then Data tier -> Logic tier -> Presentation tier) But MVC is triangular architecture. (Control update View and Model. Model update View.)
  • MVC can include in presentation tier (Mobile applications, Angular like js frameworks etc...) and Logic tier (J2EE, Laravel, etc...) in 3 tier architecture.
  • Layers in 3 tier can implement in different network nodes. But typically elements in MVC implement in same network nodes.



回答13:


I dont think MVC will change anything or help you build better or robust system. 3 tier architecture is successful and sufficient system. I/you can build very comprehensive and robust system in it. We all know a complex or real life website takes a lot of interaction between all the layers. I personally believe php for that reason has advatage over .net. If u ask a nerdy ass arrogant programmer to build a simple forum system in .net he will scratch his head over which control to use to render it. Then he will combine data grid with some repeater... But later on if u simply ask to add comment section or image, he will be like how the heck i do it? On the other hand in php... U can mix in html with server code to achieve any presentation layer easily... So dont brag about architecture as they have equal advatages and disadvantages. But ask what have you built?



来源:https://stackoverflow.com/questions/4577587/mvc-vs-3-tier-architecture

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