[[tracing:intro|Intro]]
[[tracing:ex1|Ex1]]
[[tracing:ex2|Ex2]]
[[tracing:ex3|Ex3]]
====== Context: Points in groups ======
===== Specialized tracing =====
**Task:** Pass the suite ''tests.PointGroupLog''.
Write an aspect to log whenever a ''Point'' is added to a ''Group''. Note that this requires a dynamic ''instanceof'' test, because in principle any figure element can be added to a group. The log message should simply be:
adding Point
Use the ''args'' primitive pointcut. Besides exposing context objects, ''this'', ''target'' and ''args'' can also be used to include a dynamic type test in the pointcut.
With your aspect you should be able to pass the tests of suite ''tests.PointGroupLog''.
===== Extension to invariant checking =====
**Task:** Pass the suite ''tests.PointGroupInvariant''.
Add similar advice to ensure that a ''Point'' is never added to more than one ''Group''. If this invariant is violated, the advice should throw an ''IllegalStateException'' that uses the string representation of the first group as its message.
Take a look a the implementation of the test case to see what is precisely expected.
Use an inter-type field declaration to associate a field of type ''Group'' with each ''Point'' object. Check and set this field from the advice.
----
After you have completed the exercise, remove your aspect from the build path; then return to the [[:start|Overview]].