First let me note, that I use AspectJ and I like it, but what else can I do with it.
I know AspectJ can be/is used for Logging. In some cases it is used for Transaction controlling – mostly implemented in conjunction with annotations. AspectJ can also be used to enhance classes with (code-generated) methods, like Spring Roo does.
But I believe AspectJ and AOP in general, can be used for more than: logging, transaction controlling, and simulation partial classes.
So what are other useful use cases for AspectJ and AOP?
AspectJ is very mature, powerful and widely used in today's enterprise Java frameworks like Spring. Spring uses AspectJ to make it easy for the developers to use Transaction Management, or applying security (using Spring Security) in your application.
@AspectJ refers to a style of declaring aspects as regular Java classes annotated with Java 5 annotations. The @AspectJ support is enabled by including the following element inside your XML Schema-based configuration file.
@AspectJAutoProxy. Fashioned after Spring XML's <aop:aspectj-autoproxy> , @AspectJAutoProxy detects any @Aspect beans and generates proxies as appropriate to weave the advice methods in those aspects against other beans in the container.
An aspect weaver takes information from raw classes and aspects and creates new classes with the aspect code appropriately weaved into the classes.
EDIT
Although many years passed since I gave this answer I decided to add the following to make the answer more complete.
false
in some conditions but should return true
. You can fix this using AspectJ. The Wikipedia entry gives you a few more examples (but not that many). Typically, Aspect Oriented Programing should be use only to implement simple behaviours that are not part of core concern of a class and are common to different classes. As soon as you begin to put too much logic in your aspects, the code becomes really unreadable.
The aspect you suggest (logging, transaction, ...) are the most commonly used. I would add security as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With