Implementation of Observer / Observable pattern in Java with AspectJ
For example, you can do the following line to instantiate the object Point:
Point point = new Point(1, 1);
Then, you can instantiate observers:
PointObserver1 pointObserver1 = new PointObserver1();
PointObserver2 pointObserver2 = new PointObserver2();
Finally, you can add observsers to your observable point:
point.addObserver(pointObserver1);
point.addObserver(pointObserver2);
Go in src/Core/Observable.aj
, and add the following line replacing Fraction
with the name of your class:
declare parents: Fraction implements Subject;
-
Download and add AspectJ to your project, then add AspectJ dependencies:
-
Set AJC compiler:
- AspectJ - AspectJ is an aspect-oriented programming (AOP) extension for the Java programming language.