What is the basic difference between MVC and 3-tier architect开发者_高级运维ure?
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.
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.
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.
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.
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.
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.
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
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)
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.
- 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.
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?
精彩评论