../../AspectXLib/Observability/Observer/aspects/Observer.ax
DivObs
and ModObs
.
Both classes implements update()
method that is to be called by subject class
Subject
whenever its internal state changes. The internal state of the
Subject
class can only be changed by calling its setVal()
setter method.
This aspect is implemented through five advices. The first advice inserts the code that initialize
registered observers. The second advice adds the observer declarations to the subject.
The third advise inserts update()
calls to the setter method of the subject. The
fourth and fifth advices add the necessary header files to the respective files.
Pointcuts | |
function | targetMethodImplementation |
Points to the implementations of the method Subject::setVal | |
unit | targetImplementationUnit |
Points to all units that contain implementations of methods that must be
modified | |
class | targetClass |
Points to the target class to which declarations of observers should be added | |
unit | targetClassDeclaration |
Points to the units that contain the declaration of the target class | |
constructor | constructorImplementation |
Points to the target class constructors | |
Advices | |
add | addInitializers |
Add the initializers that sets up observers | |
add | addObserversDeclaraion |
Add observers to the class declaration | |
end | addObserverNotification |
Add observer notification instructions to the method that changes the state of the
subject | |
add | addIncludesToDefinition |
Add the #include preprocessor instructions | |
add | addIncludesToDeclaration |
Add the #include preprocessor instructions |
Subject::setVal
.
This is the only method in the base code that changes the state of the
observed object.
Subject
.
Triplet: constructor add initializer initializer
_div
of type
DivObs
that takes the observed value and
divides it by 4 and
_mod
of type
ModObs
that takes the observed value and
divides it by 3. Both observers output the reminder computed
using modulo operation.
Refers to global pointcut: constructor constructorImplementation
Triplet: class add declaration
attach()
method of subject, however using aspect it is possible to insert the full list of observers
directly to the subject (if the observers do not change during the program execution).
Refers to global pointcut: class targetClass
Triplet: function end codeFragment
notify()
method of subject, however using aspect it is possible to insert the full list
update()
calls directly to the base code
(if the observers do not change during the program execution).
Refers to global pointcut: function targetMethodImplementation
Triplet: unit add include
#include
preprocessor instructions.
Both classes defined in included header files are needed as they are used
in the class declaration to declare member variables
(observers) _div
and _mod
.
Refers to global pointcut: unit targetClassDeclaration
Triplet: unit add include
#include
preprocessor instructions.
Both classes defined in included header files are needed as they are used
in the setVal()
method to call update()
method
of observers _div
and _mod
.
Refers to global pointcut: unit targetImplementationUnit