8 CHAPTER 1: Introducing Java Web Development
Each layer in Figure 1-4 is an area of concern, for the application. For instance, the web layer deals
only with employing the web tier components of Java EE. Having different layers in an application
results in what is called a separation of concerns. In terms of implementation, this separation of
concerns is achieved using coarse-grained interfaces.
The concern is the feature, functionality or business functions with which the application’s
developer needs to be concerned. Crosscutting such concerns is inherent in complex systems
and leads to code scattering, which is when code for one concern spans many modules, and
code tangling, which is when code in one module concentrates on addressing multiple concerns.
Code scattering and code tangling lead to a lack of clarity, redundancy, rigidity, and continuous
refactoring. Figure 1- 5 illustrates how the system services of logging, transaction, and security
crosscut the business functions of the application.
BookService in Figure 1-5 is too involved with the system services. Each object knows and is
responsible for logging, security, and transaction. A method, for example, to purchase a book in
BookService should be concerned only with how to purchase the book and not with whether it is
Figure 1-5. BookService involved with system services
Figure 1-4. A generalized view of layers in an enterprise application