Observer Aspect
[Observability Group]

This aspect is defined in file: ../../AspectXLib/Observability/Observer/aspects/Observer.ax

Aspect Description

Sample aspect program that implements the observer design pattern. This aspect demonstrate the simplified observer design pattern implementation where the subject has a hard-wired number of objects. The subject "pushes" updates to the observers.

There are two observes in this example -- classes 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.
Author:
A. Pasetti, O. Rohlik

Pointcuts

functiontargetMethodImplementation
  Points to the implementations of the method Subject::setVal
unittargetImplementationUnit
 Points to all units that contain implementations of methods that must be modified
classtargetClass
  Points to the target class to which declarations of observers should be added
unittargetClassDeclaration
  Points to the units that contain the declaration of the target class
constructorconstructorImplementation
  Points to the target class constructors

Advices

addaddInitializers
  Add the initializers that sets up observers
addaddObserversDeclaraion
  Add observers to the class declaration
endaddObserverNotification
  Add observer notification instructions to the method that changes the state of the subject
addaddIncludesToDefinition
  Add the #include preprocessor instructions
addaddIncludesToDeclaration
  Add the #include preprocessor instructions

Pointcut Documentation

function targetMethodImplementation (source)
Points to the implementations of the method Subject::setVal. This is the only method in the base code that changes the state of the observed object.
unit targetImplementationUnit (source)
Points to all units that contain implementations of methods that must be modified. This pointcut identifies all the source files that contain an implementation of the target method.
class targetClass (source)
Points to the target class to which declarations of observers should be added. The class is identified by its name: Subject.
unit targetClassDeclaration (source)
Points to the units that contain the declaration of the target class.
constructor constructorImplementation (source)
Points to the target class constructors.

Advice Documentation

add addInitializers (source)

Triplet: constructor add initializer initializer

Add the initializers that sets up observers. In this example two observers are considered: _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

add addObserversDeclaraion (source)

Triplet: class add declaration

Add observers to the class declaration. This is normally done using 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

end addObserverNotification (source)

Triplet: function end codeFragment

Add observer notification instructions to the method that changes the state of the subject. This is normally done using 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

add addIncludesToDefinition (source)

Triplet: unit add include

Add the #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

add addIncludesToDeclaration (source)

Triplet: unit add include

Add the #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