Writing Mixins using AspectJ

java.net has a nice long article on Writing Mixins using AspectJ. They use the example of JavaBean property change event listeners, which up to this point has been a total pain to write. Using AspectJ, you can whisk that code away into its own aspect. Your tradition bean looks clean and beautiful again, while retaining the nice functionality of event listener notification.

>Aspect-oriented programming complements object-oriented programming in many ways. One interesting complementary feature is behavior composability. This means that it should be possible to compose a class by adding behavior from different classes. OO uses inheritance and many patterns to add behavior to existing classes. AOP allows us to use mixins without changing the class inheritance hierarchy or otherwise changing the code.

>Mixins enable us to uniformly extend a set of classes with a set of fields and methods. Java does not support mixin-based programming. This article shows what mixins are and explains how AOP constructs in AspectJ allow us to use this technique to isolate crosscutting concerns, with an example. It starts with a plain Java implementation and ends with an AspectJ 5 implementation.

Popular posts from this blog

Lists and arrays in Dart

Converting Array to List in Scala

Null-aware operators in Dart