Object-Oriented Programming 2023/24

Exercise 9



Continue working on your projects. Consider applying aspect-oriented programming in your projects.

To install the support for aspect-oriented programming in Eclipse, follow these instructions.

The simplest way to use the AspectJ programming language in your projects is to create a new AspectJ project and then to copy your own source code into it.

To apply aspect-oriented programming in an existing Java project in Eclipse, a conversion to an AspectJ project can be used (make a right click on a project and choose Configure/Convert to AspectJ project). The conversion actually only adds the AspectJ Runtime Library to the project and sets the AspectJ compiler as its compiler, which can be made manually.

The AspectJ compiler is also available standalone on the AspectJ website.



  1. Observe how aspect-oriented monitoring and control of point coordinates works in the examples with the Point class from the lecture (you can create a separate Eclipse project for each case):
    1. Simple access monitoring (the AccessMonitoring folder)
    2. Different types of the after advice in access monitoring (the AccessMonitoring-after folder)
    3. Monitoring the range of point coordinates (the RangeMonitoring folder)
    4. Preventing the operations with point coordinates outside the permitted range (the RangeControl1 folder)
    5. Scrolling the point in the case of the operations with point coordinates outside the permitted range (the RangeControl2 folder)
    6. Scrolling the shapes in the case of the operations with point coordinates outside the permitted range (the RangeControl3 folder)
    The PointMonitor aspect, which you can try out if you want to better understand frequently applied pointcuts, is included in the last case. This aspect also demonstrates solving the problems with recursively applied pieces of advice.
  2. Experiment with the game from the lecture code, which contains applied aspects for logging and adding shields to knights.
  3. The Observer design pattern is implemented in the game, too. One aspect was sufficient for this ObserveWarriorEnergy. Note how this aspect introduces elements of the pattern into the Clash a ClashWindow classes and how are these put into function using advice. The original, object-oriented implementation of the Observer design pattern has been preserved in the form of comments for comparison. Try to implement to the ObserveWarriorEnergy aspect including your own clash observer that you have implemented in exercise 3.
  4. (non-compulsory task) Experiment with the aspect-oriented implementation of the example of applying the Observer design pattern to temperature sensors. For comparison, recall the object-oriented implementation of this example (available in the same archive), which has been provided with lecture 3.


Valentino Vranić
vranic at stuba.sk