Aspect-oriented programming: Difference between revisions

Content deleted Content added
spacing
Tags: Mobile edit Mobile web edit Advanced mobile edit
AspectJ's join-point model: MOS:LISTGAP (ordinary list and pre block markup unfortunately not compatible)
Tags: Mobile edit Mobile web edit Advanced mobile edit
Line 97:
===AspectJ's join-point model===
{{Main article|AspectJ }}
{{unordered list
*| The join points in AspectJ include method or constructor call or execution, the initialization of a class or object, field read and write access, exception handlers, etc. They do not include loops, super calls, throws clauses, multiple statements, etc.
*| Pointcuts are specified by combinations of ''primitive pointcut designators'' (PCDs).
 
:"Kinded" PCDs match a particular kind of join point (e.g., method execution) and tend to take as input a Java-like signature. One such pointcut looks like this:
* The join points in AspectJ include method or constructor call or execution, the initialization of a class or object, field read and write access, exception handlers, etc. They do not include loops, super calls, throws clauses, multiple statements, etc.
* Pointcuts are specified by combinations of ''primitive pointcut designators'' (PCDs).
 
:"Kinded" PCDs match a particular kind of join point (e.g., method execution) and tend to take as input a Java-like signature. One such pointcut looks like this:
 
execution(* set*(*))
 
:This pointcut matches a method-execution join point, if the method name starts with "<code>set</code>" and there is exactly one argument of any type.
 
"Dynamic" PCDs check runtime types and bind variables. For example,
Line 111:
this(Point)
 
:This pointcut matches when the currently executing object is an instance of class <code>Point</code>. Note that the unqualified name of a class can be used via Java's normal type lookup.
 
"Scope" PCDs limit the lexical scope of the join point. For example:
Line 117:
within(com.company.*)
 
: This pointcut matches any join point in any type in the <code>com.company</code> package. The ''<code>*</code>'' is one form of the wildcards that can be used to match many things with one signature.
 
Pointcuts can be composed and named for reuse. For example:
Line 123:
pointcut set() : execution(* set*(*) ) && this(Point) && within(com.company.*);
</source>
:This pointcut matches a method-execution join point, if the method name starts with "<code>set</code>" and <code>this</code> is an instance of type <code>Point</code> in the <code>com.company</code> package. It can be referred to using the name "<code>set()</code>".
 
*| Advice specifies to run at (before, after, or around) a join point (specified with a pointcut) certain code (specified like code in a method). The AOP runtime invokes Advice automatically when the pointcut matches the join point. For example:
 
after() : set() {
Display.update();
}
 
:
:This effectively specifies: "if the ''<code>set()</code>'' pointcut matches the join point, run the code <code>Display.update()</code> after the join point completes."}}
 
===Other potential join point models===