Το γνωρίζω ότι γίνεται μεγάλο μπέρδεμα για το τί σημαίνει layer και τί σημαίνει tier, και μάλιστα η Microsoft ευθύνεται σε μεγάλο βαθμό γι αυτό. Πολλά από τα παλαιότερα άρθρα του MSDN χρησιμοποιούσαν τους όρους σαν να είναι ταυτόσημοι. Τα τελευταία χρόνια όμως οι όροι έχουν ξεχωρίσει γιατί η ανάπτυξη layer έχει τελείως διαφορετικές ανάγκες, τεχνικές και best practices από την ανάπτυξη tiers. Μάλιστα, αυτό που είναι σωστό στη μία περίπτωση μπορεί να είναι λάθος στην άλλη. Για παράδειγμα, όταν καλείς ένα service σε άλλο υπολογιστή είναι καλύτερο να κάνεις μία μεγάλη κλήση παρά πολλές μικρές, γιατί το κόστος είναι πολύ μεγάλο. Αντιθέτως, το UI layer συνήθως θέλει να κάνει πολλές μικρές κλήσεις στο business layer.
Αντιγράφω λόγω τεμπελιάς από το άρθρο "Pragmati Architecture: Layering" του Ted Neward :
-------
A layer is a logical separation of software, a basic separation of concerns at the developer level, so we can more easily partition the responsibilities of the system. This is further documented in [POSA1], where the Layers pattern states that using Layers "helps to structure applications that can be decomposed into groups of subtasks in which each group of subtasks is at a particular level of abstraction." In other words, it's classic separation of concerns: split the various tasks involved in an enterprise system—the retrieval of data, the storage of data, the execution of business rules against that data, the display of data, the collection of input, and so on—into components or subsections, so that we can more easily track what is happening where and when. Naturally, the most common division of labor is into presentation, logic, and data-access layers. Note, however, that we're not immediately making any presumption about where each of these layers will run—not yet.
A tier, on the other hand, is a physical layer of hardware, usually a computer of some form, on which some or all of our system can run. Traditional client/server computing—writing a program that executes SQL statements against a database running on a separate server—is a two-tier system. The World Wide Web we all enjoy on a daily basis is also built on the backs of a two-tier approach, where one tier, the client machine, sits in somebody's home or office and remotely accesses a second tier, sitting in a server room somewhere. And so on.
---------
Τα components του κάθε tier μπορούν να έχουν το καθένα το δικό του presentation layer (στον client είναι το UI, στον server είναι η κλάση ή τα web services που εμφανίζει προς τα έξω), business layer και data layer (local cache στον client, η κυρίως βάση στο server), με διαφορετικές όμως αρμοδιότητες. Δεν μπορείς όμως να πεις ότι τα components ενός layer μπορούν να έχουν πολλά tiers. Από την άλλη, η χρήση πολλών layer σε μία εφαρμογή είναι χρήσιμη στις περισσότερες περιπτώσεις. Η χρήση πολλών tiers πολλές φορές πρέπει και μπορεί να αποφευχθεί. Μία single user desktop εφαρμογή μπορεί να έχει UI, business layer και data layer, δεν χρειάζεται όμως ξεχωριστό server.
Ρίξε μία ματιά και στο υπόλοιπο άρθρο καθώς εξηγεί και τους λόγους για τους οποίους επιλέγει ή δεν επιλέγει κανείς μία N-tier αρχιτεκτονική. Αν ενδιαφέρεσαι να ασχοληθείς σοβαρά με N-tier εφαρμογές αξίζει να διαβάσεις το βιβλίο "Patterns of Enterprise Application Architecture" του Martin Fowler, το οποίο καλύπτει θέματα data access, concurrency, business logic, session management κλπ. Θέματα τα οποία είναι εξαιρετικά χρήσιμα όταν φτιάχνεις μία N-tier εφαρμογή.
Παναγιώτης Καναβός, Freelancer
Twitter: http://www.twitter.com/pkanavos