RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Explore Model Driven Architecture and Aspect-oriented Programming, Birds of a Feather

In recent years, two new trends in software engineering have been established—Aspect-oriented Programming (AOP) was developed to extend and ease programming, and the Model Driven Architecture (MDA) was introduced to take full advantage of the power of modeling. Many people are confused when confronted with both AOP and MDA. This article provides a crash-course on both topics and explains the differences and similarities between the two.

lthough AOP and MDA were developed from very different viewpoints: programming vs. modeling; weaving many inputs into one output vs. creating many outputs from one input, there is a great deal of common ground between them and both techniques are used for identical purposes. There is no need to choose between them. They complement each other and can be used together successfully.

One very positive aspect of both AOP and MDA is that they have brought our attention back to issues like modularization and abstraction; issues that were considered to be very important in the 1980s, but slipped away in the 1990s. You should not forget that the attention to these issues was very fruitful—it was the driving force behind the advent of object-oriented programming and object-oriented modeling, and as such, has brought us the UML. It will be very interesting to see what it will bring us in the 21st century. It may be called MDA, AOP, or it may have a completely different name, but it will no doubt be an important step forward for the industry.

Aspect-oriented Programming
The key to AOP is modularization. Each program contains aspects that are not specific for that application domain. For instance, the way error handling, logging, or tracing is handled is often identical over multiple domains. AOP tells us that these aspects should be contained in different modules, and indeed aspect is the name used for such a module. The modules that contain the application-specific code and the non-specific aspect module, or modules, are then woven together to create the application. (See Figure 1.)

Figure 1. Aspect Weaving: Application code and aspects are woven together to get the finished product in AOP.
The application-specific code and the aspects can be developed independently. The application-specific code need not know what aspects will be added, leaving the developer to concentrate on implementing the required functionality—the business logic. Likewise, the author of the aspects does not need to know the application-specific code. The only knowledge necessary for writing aspects would be the join points. Join points are identifiable events in the execution of a program. The developer of a logging aspect, for instance, would have to know about method calls and the aspect would specify that whenever a method is called, a message would be added to the log.

Join points can be identified by the aspect using pointcut expressions. Pointcut expressions specify join points, much as classes specify object instances. In the example below, the pointcut publicMethods is defined to include all methods of any class in the package org.apache.cactus or any of its subpackages. Before execution of such a method the Logger.entry() method is called, and after execution a call to the Logger.exit() method is placed.
 public aspect AutoLog{
    pointcut publicMethods() :
            execution(public * org.apache.cactus..*(..));
    before() : publicMethods(){
    after() : publicMethods(){
Another term you need is advice, this is the set of statements that should be executed whenever a join point occurs. In the AutoLog example above, there are two advices: the before and after advice. The last term that you should be familiar with is crosscutting concerns. This is behavior that cuts across the typical divisions of responsibility, such as logging. Aspects are most-often used to define such crosscutting concerns.

There are different forms of AOP. The Java-based AspectJ is probably the best-known aspect-oriented language. Other well-known examples are Spring AOP and AspectC++. See AOSD.net for more tools and aspect-oriented languages.

In short, AOP takes two or more disjointed parts of an application and weaves them together to produce the final result. The link between the parts is formed by join points, which are specified by pointcuts. Aspects are commonly used for logging, tracing, debugging, and profiling, or performance monitoring or testing of diagnostic systems, and to display updated notifications, mainly security, context passing, and error handling.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date