Intro Ex1 Ex2 Ex3 Ex4

Caching: Invalidate (part II)

Task: Pass tests.Invalidation2a and pass tests.Invalidation2b.

Of course, the previous aspect didn't really solve the problem. What if a Point that is part of a Group moves? Whenever either of the fields of a Point are set it should invalidate the caches of all enclosing groups.

Store the enclosing Group as a newly introduced field of a FigureElement (intercept the add() method of Group to populate this field). When the FigureElement moves, the cache of its enclosing group should be invalidated (if there is an enclosing group and if there is a cache value for this group).
If you use aspectOf, but no corresponding aspect instance can be found, the AspectJ runtime will throw the NoAspectBoundException.

A correct implementation should at least pass the tests of suite tests.Invalidation2a.

However, check if you really did it correctly by also running the suite tests.Invalidation2b. If you pass, congratulations! Otherwise, you have fallen prey to our cruel trap: Remember that whenever a point moves it should invalidate the caches of all enclosing groups (recursively).


When done, remove your aspects from the build path and return to the Overview.