Aspect-oriented programming aims at improving the modularity of software systems, by capturing inherently scattered functionality, often called crosscutting concerns, making the evolution of such systems easier and more manageable. In order to obtain this, AOP adds an extra abstraction mechanism, called an aspect, on top of existing modularization mechanisms such as functions, classes and methods. Aspects allow developers to face up the problems of scattering and tangling by reducing the spread of code belonging to a certain concern over different components.
During the software development phase the product concept that was identified and researched in the pre-development phase becomes a reality. Systems requirements are translated into design specifications that are in turn translated into software code.
For a given software development project, the particular breakdown of the life cycle and the activities performed within each phase will depend very much on the type of application, the method and development tools used and the target implementation environment.
The emphasis throughout the development phase should be on getting a workable and acceptable version of the product to market in the minimum time. It is always necessary to guard against 'perfect solutions'.
Aspect Oriented Programming provides explicit constructs to develop software systems whose crosscutting concerns are better modularized because they are no longer tangled together and they are clearly separated from the principal decomposition. In order to extend the benefits of aspect-oriented programming to already existing systems, a significant reverse and re-engineering effort is required. The effort consists, first of all, of analyzing the existing application source code looking for those portions that implement the crosscutting functionality. The second part of the work is the transformation of the existing program into an aspect-oriented reformulation. In order to take advantage of the potential benefits of the AOP style of programming, there is a need for migration support of existing applications and systems.
Each phase of the software project - design, implementation, testing, and maintenance - accentuate certain activities. Aspect-oriented programming has a different role in each of these phases.
The design phase provides the detailed specifications of how the software should be developed. This is more technical than analysis specification, and at this point of time, the developer needs to think about how the software can realize the requirements into a working system. A way to use AOP is described below.
Crosscutting concerns recognition - This step is part of mapping requirements to modules. Possible crosscutting concerns may be described using an adjective or adverb, which reduces the effort needed to modularize them in the conventional fashion.
Initial design Core concerns - The core concerns are first designed to apply easier crosscutting concerns, because they will simplify the specification of weaving rules.
Just as the design phase may include some analysis efforts approached from a computational standpoint, the implementation phase essentially always includes design efforts. Implementation-level design is a balancing activity, where in-principle executable models, implementation languages and tools, performance requirements, and delivery schedules must finally be combined, while maintaining correctness, reliability, extensibility, maintainability and related criteria.
With AOP, core and crosscutting concerns may be implemented as easily as possible. If AOP is used, much of the process and methodology is mostly unchanged from OOP. The following principles may be used to determine where AOP is necessary to appear:
Well-factored written code - Specific core functionality is implemented by an operation which is an ideal scenario. If each method maps to a specific functionality, it will achieve the right level of granularity. With this, AOP can be applied consistently throughout a project.
Consistent naming conventions usage - Pointcuts that use wildcards to capture join points not only make writing aspect easier, but also ensure that the aspects apply to all new modules introduced in the system.
Any visible tangling and scattering appearing - While implementing the core concerns, code tangling and code scattering may appear. This is possible when crosscutting concerns are implemented using OOP that may actually be candidates for AOP.
The following tasks are performed when the crosscutting concerns are implemented:
Join points identifications - In the code, places where crosscutting behavior is needed are identified. The pointcuts are expressed according to the captured join points: name-based pointcuts, control-flow pointcuts, and so on.
Let's consider a check for a common pre- or post-condition for multiple operations in a class. With conventional refactoring, the check is included in a method and can be called from all the places where it is required, instead of repeating a block of code in all the places. In aspect-oriented programming, an aspect is written to crosscut that check into all required methods, and there is no need to call the method performing the check from multiple places.
Having analyzed, designed and implemented a solution, the next step is to run the algorithm with test data and making sure that it has no logical errors.
In the testing phase, the programmer has to consider weaving processes and imagine how a woven program behaves, because targets of testing are not individual objects.
There is a break between the design phase and the testing phase in AOP. The following examples are possible scenarios:
Creating test cases - Test programs can be created with modification of the behavior and without many changes in the code.
Implementing performance testing - Many performance problems are uncovered during close-to-real deployment, but it is not available during development phases. With AOP it is possible to perform dynamic profiling in an environment by monitoring aspect during testing.
Maintenance is the development phase that occurs to a system after it has been delivered for its original purpose. This is an important phase for software projects because most development effort goes toward maintenance. It has two activities: adding implementation to meet new requirements and fixing bugs found in the testing phase.
The following tasks may be handled in this phase:
Creating protection walls - This task ensures that new changes do not modify other parts of the system and prevent introduction of new bugs.
AOP does not call into question what has been achieved through OOP. AOP simply adds new concepts that allow improving object-oriented applications by making them more modular. In addition, it simplifies the development process by allowing the separation of development tasks. For example, specialized experts can develop highly technical functionalities, such as security, and aspects allow easier integration of these functionalities into the rest of the application.
No doubt the adoption of AOP will take a long time and require effort, but it can be done gradually when the need is clearly identified.
Enterprise applications need to address many crosscutting functionalities: transaction management, security, auditing, service-level agreement, monitoring, concurrency control, improving application availability, error handling, and so on. Many enterprise applications use AOP to implement these functionalities. Virtually every project that uses Spring uses AOP.
Web and application servers, like open source SpringSource dm Server, support developing enterprise application based on OSGi. It uses AspectJ to implement various crosscutting functionalities, such as First Failure Data Capture (FFDC), context collection, tracing, and policy enforcement. The SpringSource tc Server uses AspectJ to implement monitoring of deployed applications.
Application frameworks can use AOP effectively to target specific crosscutting functionalities while keeping their structure modularized. Spring includes aspects for injecting dependencies into domain objects. Frameworks that use AspectJ as their foundation have started to appear as well.
AspectJ makes implementing a flexible monitoring scheme a breeze. Therefore, many tools use AspectJ as the underlying technology (Glassbox, Perf4J, Contract4J) and several commercial products also use AspectJ to implement monitoring solutions.
AspectJ itself uses AspectJ to extend the JDT complier to support AspectJ constructs. AJDT uses AspectJ weaving through OSGi-based weaving service implemented by the Equinox Aspect project to better integrate with the JDT in Eclipse. This recent change enabled AJDT to provide a much better user experience. Scala IDE for Eclipse also followed the same route to provide a better experience for Scala developers.
In conclusion, programmers are slowly realizing the importance of aspect-oriented programming as crosscutting happens to be a new modularity principle. AOP is all set to be an important programming methodology given that its advantages are manifold. It also eliminates some of the difficulties prevalent in designing, developing and maintaining good software systems.
by Ovidiu Mățan
by Ștefan Bălan
by Oana Călugar
by Adrian Ivan
by Cosmin Jeler
by Diana Ciorba
by Ovidiu Mățan
by Ovidiu Mățan