Aspect-Oriented Programming: A Tool for Internationalization
About a year ago, aspect-oriented programming (AOP) was considered quite specialized in nature. Nowadays, AOP forms an important part of frameworks such as Spring. Why is this so? One reason is the increasingly decoupled manner in which software is developed. A great example of this is Spring's use of inversion of control, where the order of code execution is dictated by XML files. So AOP will most likely become increasingly mainstream.
An important aspect of AOP is that, used in isolation, it can facilitate a range of useful separations of concerns. One such area is internationalization (often called I18N because of the 18 characters between the first and last letter of the word). I18N is big business in a global software marketplace. In this article I'll use AOP to show how part of the I18N problem can be solved with the use of aspects in an additive, not-too-invasive manner. I call this low-touch programming (LTP).
The Case for Low-Touch Programming
I use I18N as an example in this article, but low-touch programming has other compelling benefits and applications. Technology customers now demand three elements in their software and system procurements:
- Low cost
- Flexible solutions
- Commodity technology
Examples of systems that fulfill these three needs include the various flavors of Linux and the many open-source products and toolkits. When Sun open-sources Java, as promised, it's likely the open-source software development effort will accelerate. This may, in turn, increase the consumer appetite for complex products that have the above three elements. What does this growth mean to programmers?
As engineers, we must strive to meet these three needs, and one useful approach is to use low-touch programming. With LTP, you add or modify code in a manner that's as noninvasive as possible—which is just good design practice. Ideally, LTP should allow you to drop working classes into an operational product. The dropped-in classes then provide any required extra capabilities and help fulfill at least the first two benefits, low cost and flexible solutions. AOP is an unusual technology that can facilitate such class insertion and other LTP needs.
To begin, I'll define a few simple I18N requirements. Then we'll launch into some Java examples to fulfill these requirements, and finish up with the AspectJ code. (AspectJ is an aspect-oriented extension to Java.)