Aspectj Cookbook
One slightly controversial feature of the AspectJ developer's toolkit is the ability to monitor any accesses or modifications that may occur on a class's attribute. AspectJ provides this capability in the form of the get(Signature) and set(Signature) pointcuts that are the focus of this chapter. Anyone who has practiced traditional object-oriented techniques will be a little worried when they hear this as it effectively breaks encapsulation, especially if the attributes being monitored are declared protected or private. It is good advice to think carefully before you decide your aspect needs to have direct access to a class's internals to avoid unnecessary tight coupling between your aspects and your classes. However, sometimes a cross-cutting concern requires this level of intimacy with a class's to apply the aspect effectively. Used judiciously the get(Signature) and set(Signature) pointcuts showcased in this chapter can provide a powerful means of advising your classes, but they must be used carefully to ensure that you are not making your classes and your aspects needlessly brittle. |