Java Reference
In-Depth Information
Aspect‐oriented programming (AOP) aims to add behavior to existing code or applications to solve
common concerns. It is fairly normal to receive a new logging or security request in the middle of
the development cycle. Such requests may consume a huge amount of time in refactoring existing
code even though the logging code is a bunch of repetitive lines. Such common concerns, whether
they appear in the middle of the development cycle or in the design phase of the project, are called
cross‐cutting concerns and can be addressed with AOP.
AOP became a popular programming paradigm during the past decade. Although Java did not
offer a full‐l edged out‐of‐the‐box solution, some well‐implemented third‐party frameworks offered
AOP. AspectJ and Spring are widely accepted and have been used for a long time in Java‐based
projects. Java also had a similar but more basic approach with servlet i lters, although it is limited
to web requests. With servlet i lters, any request or response can be intercepted, and any additional
behavior can be added.
Java EE adopted AOP and introduced the interceptor concept. Each update to Java EE brought new
functionalities and unleashed the full potential of AOP to the Java EE platform.
AOP is not classii ed as a design pattern but is accepted as a programming paradigm. Neither
the GOF book nor Head First Design Patterns 2 discusses aspects. However, if either one did, an
appropriate description would be “Provides a way to change execution behavior at run time (or
compile time) to address cross‐cutting concerns in the existing code base.”
AOP relies on code injection during compile time or run time to add the desired behavior or
functionality to each point of an existing code base that matches the given injection criteria.
Frameworks that perform compile‐time injection usually out‐perform, but they produce class i les
that do not match the source code line by line because of the injected code. Runtime injection does
not modify the source or class i les and performs injection by intercepting calls and executing the
desired code before or after the original execution order.
AOP can prove to be useful if it is necessary to add a repetitive action, such as logging or security,
to a code base. The aspects can be turned on or off depending on the environment or phase of the
project. Aspects can dynamically add the desired behavior to running code. They dynamically
decorate the method calls just as the decorator pattern decorates objects.
We had just i nished development of a web application and were completing the
i nal phase before going live. After completing functionality and user acceptance
tests, we needed to submit the application to security trials. A team of security
experts was hired to test our system for vulnerabilities. Because the application
before ours was hacked and leaked important data, the security testing was taken
very seriously.
Search WWH ::

Custom Search