25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 8 ■ Give Advice to Your <strong>Spring</strong> Application<br />

Figure 8-1. Tangling and Scattering Code<br />

Figure 8-1 shows how your logging mechanism is in every method of your SearchEngine implementation, and<br />

that it could be in other classes like the DocumentService or MediaService classes. The code is all over the place! This<br />

is called scattering and its implementation is not modular. But that’s not all. As I mentioned before, you can have the<br />

same code, such as authorization or audit, in places where there is a particular business logic happening, making it<br />

not cohesive. This is called tangling. There should be a better way to solve these issues.<br />

AOP to the Rescue<br />

You need to start thinking about how to modularize your code into independent modules. But how can you<br />

accomplish that? Aspect-oriented programming (AOP) was created to accomplish this hard task by modularizing<br />

this cross-cutting functionality into better manageable modules. In other words, AOP is going to take care of your<br />

concerns (such as logging, authorization, and audit, in your case), so you can focus only on the business logic without<br />

having to worry about checkpoints or logging.<br />

91

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!