Section 2.2. Three-Tier Applications

2.2. Three-Tier Applications

Before we dive into writing our code, let's take a moment to talk about some architectural principles. This discussion will set the stage for this chapter and the rest of the book.

The parts of a J2EE application fall into three basic tiers:

  • The presentation tier is the collection of J2EE components that comprise the UI. For web applications, this tier includes components like Servlets and JSPs.

  • The business tier is so named because it is where your business logic lives. The technologies that live here include EJBs and MDBs.

  • The persistence tier is where your data is stored for the long term. It generally involves a relational database, but isn't limited to that. You could store your data as XML, serialized JavaBeans, or even plain old ASCII text files.

In a well-engineered application, components in each tier are "highly cohesive" and "loosely coupled". By highly cohesive, we mean that each component should do only one thing. By loosely coupled, we mean that components across the tiers shouldn't depend on one another unnecessarily.

For example, a getCars( ) method call should return only data. The data shouldn't be preformatted into HTML. If it is, your data tier knows too much about the presentation tier. The two tiers are highly coupled.

An unfortunate side effect of this coupling is that deciding to add a new presentation technology later (like a Swing client) will force you to rewrite a portion of your persistence tier as well. If instead your persistence tier returns data and lets the presentation tier concern itself with the formatting, then you can reuse your persistence tier across multiple UIs. Loosely coupled tiers encourage reuse.

You also could argue that the persistence tier fails the highly cohesive test. It is concerned with too many thingsdata and presentation. A clean separation of concerns is what we are hoping to accomplish.

This notion of tiers guided both the JAW Motors application architecture and the layout of this book. The book starts with the presentation tier in the first few chapters, moves through the persistence tier in the middle chapters and tackles business tier issues in the latter chapters.

JBoss at Work. A Practical Guide
JBoss at Work: A Practical Guide
ISBN: 0596007345
EAN: 2147483647
Year: 2004
Pages: 197

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: