MVC vs. 3-tier architecture?
Asked Answered
D

11

68

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

Divisibility answered 2/1, 2011 at 7:37 Comment(1)
possible duplicate of MVC Vs n-tier architectureVaricelloid
U
33

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.

Unpractical answered 2/1, 2011 at 8:8 Comment(3)
If View=Presentation,Controller=Business and Model=DAL So what is the basic difference between them? which one is better and why?Divisibility
MVC could be said to be an implementation of a three tier architecture, but can also be the top tier in and of its self.Unpractical
I agree with your 1st paragraph, but disagree with your 2nd. BL should not be in the controller. Strive for a robust Model containing the BL and a lean Controller.Naseby
G
33

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.

Gibbeon answered 17/12, 2012 at 8:16 Comment(3)
Saying that, "3-tier is a Architecture Style and MVC is a Design Pattern" is not enough. MVC is a design pattern that falls into the Architectural patterns group.Calycle
Actually MVC is an Architecture Pattern, not a Design Pattern.Bowrah
Do we use MVC for the frontend only and 3-tier for the backend?Klaxon
W
18

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.

Waxen answered 7/1, 2013 at 7:50 Comment(0)
C
13

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.

Chablis answered 26/2, 2014 at 11:38 Comment(0)
H
12

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.

Hannahannah answered 2/1, 2011 at 20:54 Comment(0)
M
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.

Molech answered 9/1, 2012 at 6:22 Comment(1)
Agreed, they are orthogonal, but complementary.Avi
R
7

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

Reasoned answered 28/7, 2011 at 12:52 Comment(2)
Well, except that it's at best only half the question. Can you delta MVC?Pippas
This answer is not related with the question. This say only 3 tier.Enterogastrone
G
6

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)

Gauldin answered 2/1, 2011 at 8:1 Comment(1)
I believe you copied this answer from Wikipedia. It's better if you cite your source. "Check Comparison with the MVC Architecture" paragraph @en.wikipedia.org/wiki/3-tier_architecturePeriphrasis
P
3

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.

Pomology answered 9/1, 2013 at 18:20 Comment(2)
this answer is a perfect example of what happened to me in an interview. One of the main reasons I did not get the job was because I did not know what MVC was but have been programming three tier for over 10 years. After researching MVC it is totally three tier mixed up. IMO three tier is superior over MVC like this user pointed out, MVC has just made a messSimpleton
Totally agree with u. Just another plus point, thanks to that triangle interaction, many web frameworks have their own way of doing "MVC" which causes a lot of confusion.Lisbethlisbon
E
2
  • 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.
Enterogastrone answered 28/7, 2016 at 1:41 Comment(0)
E
-8

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?

Embitter answered 28/6, 2014 at 9:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.