This is where
an n-tier architecture can provide a suitable structure
for your
application. The letter "n" stands for any number
of tiers. Traditionally, it starts with a basic 3-tier
model
and expands on it to allow for greater performance, scalability,
and a host of other benefits. The single most important
benefit
of an n-tiered architecture, compared to a 3-tier approach,
is breaking up the business logic from the application-server
level into a more fine-grained model. More details on this
and other benefits of an n-tiered architecture are discussed
below.
Example of an n-tiered architecture
This example shows a generic shopping-cart web application.
The tiers used for this example include the client,
presentation,
business logic, integration, and data. The client tier represents how the user interacts with
your sample application. Because this is a web-based application,
the client will use a browser for this task. For a rich
user experience, you might use Macromedia Flash MX. Additionally,
the Macromedia Flash MX footprint is small and you can include
auto-detection and auto-installation so that requiring it
in your application is seamless to the user.
The presentation tier represents the dynamic creation of
display code (HTML) that is sent to the user's browser.
This layer dynamically displays information, such as merchandise
and the contents of your shopping cart. It communicates
with the other tiers by way of outputting the results to
the client tier (browser) and all other tiers by calling
custom tags, calling database stored procedure, invoking
ColdFusion components (CFCs), calling Enterprise JavaBeans
(EJBs), calling web services, and so forth. This layer is
the glue that holds the entire application together. It
binds all of the tiers and ensures that the client sees
what was requested in the browser. A typical tool for this
tier is an application server, such as Macromedia ColdFusion
or Macromedia JRun. As I mentioned before, you may want
to use Macromedia Flash MX.
The business logic tier represents the core functionality
of your application. It performs low-level code and number
crunching. In the shopping-cart example, business logic
calculates sales tax and shipping costs and performs credit
card authorizations. Pull this logic out of the presentation
tier and place it into its own tier. Common tools you can
use to encapsulate business logic include EJBs, web services,
database stored procedures, CFCs, or very specialized JavaServer
Pages (JSP) or ColdFusion custom tags or templates.
The integration tier encapsulates the functionality required
for an application to talk to the data tier, or sometimes
the business logic tier, in an easy-to-use format. This
way, a developer working on the presentation tier can focus
on HTML and output, and simply call the custom tag, CFC,
EJB, web service, and so forth, without knowing the low-level
details of database interaction or object invocation. Furthermore,
if you change database vendors you won't break any presentation
tier code that may include vendor-specific functionality.
Simply adjust your custom tag library and let the presentation-tier
developers focus on presentation content.
Some common tools you can use to build the integration
tier are CFCs, web services, ColdFusion custom tags, or
JSP custom tags. For example, in a shopping-cart application,
you might have a simple custom tag that hides all of the
complexities of querying a database to get detailed inventory
information.
The data tier is the final tier of your application. The
most common solutions for this level are database servers
such as Oracle, MySQL, and Microsoft SQL Server. Pulling
your data into its own tier is one of the most important
steps you can take to break up an application. Not only
does it keep the data neutral (not tied into your application
server or business logic, and so forth), but it has the
added benefit of improved performance and scalability. As
your data needs increase, you can move this tier to its
own (or a more powerful) machine and eventually to its own
cluster of machines.
Applying an n-tiered architecture to a sample application
The following example illustrates how all of the tiers would
work together in the fictional shopping-cart application.
This example focuses specifically on what takes place behind
the scenes to calculate and display sales tax for an order.
First, the presentation tier calls a business tier custom
tag, EJB, CFC, and so forth that performs a series of calculations
on the contents of the shopping cart to compute a total
sales price. The business logic tier pulls up the appropriate
tax rate from the database by working with the integration
tier (a custom tag, CFC, and so forth). A simple call to
the integration tier masks the complexities of talking to
the data tier and retrieves the required tax rate so that
the business logic can finish its task. Once the business
logic tier calculates the sales tax, the presentation tier
takes over and formats the results and passes it to the
client tier (web browser) for display.
|