What's the difference between "Layers" and "Tiers"?

What's the difference between "Layers" and "Tiers"?


Solution 1:

Logical layers are merely a way of organizing your code. Typical layers include Presentation, Business and Data – the same as the traditional 3-tier model. But when we’re talking about layers, we’re only talking about logical organization of code. In no way is it implied that these layers might run on different computers or in different processes on a single computer or even in a single process on a single computer. All we are doing is discussing a way of organizing a code into a set of layers defined by specific function.

Physical tiers however, are only about where the code runs. Specifically, tiers are places where layers are deployed and where layers run. In other words, tiers are the physical deployment of layers.

Source: Rockford Lhotka, Should all apps be n-tier?

Solution 2:

Read Scott Hanselman's post on the issue: A reminder on "Three/Multi Tier/Layer Architecture/Design":

Remember though, that in "Scott World" (which is hopefully your world also :) ) a "Tier" is a unit of deployment, while a "Layer" is a logical separation of responsibility within code. You may say you have a "3-tier" system, but be running it on one laptop. You may say your have a "3-layer" system, but have only ASP.NET pages that talk to a database. There's power in precision, friends.

Solution 3:

Layers refer to the logical separation of code. Logical layers help you organize your code better. For example, an application can have the following layers.

  1. Presentation Layer or UI Layer
  2. Business Layer or Business Logic Layer
  3. Data Access Layer or Data Layer

The above three layers reside in their own projects, maybe 3 projects or even more. When we compile the projects we get the respective layer DLL. So we have 3 DLLs now.

Depending upon how we deploy our application, we may have 1 to 3 tiers. As we now have 3 DLL's, if we deploy all the DLLs on the same machine, then we have only 1 physical tier but 3 logical layers.

If we choose to deploy each DLL on a separate machine, then we have 3 tiers and 3 layers.

So, Layers are a logical separation and Tiers are a physical separation. We can also say that tiers are the physical deployment of layers.