Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Aspect-oriented programming
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Join point models== The advice-related component of an aspect-oriented language defines a join point model (JPM). A JPM defines three things: # When the advice can run. These are called ''[[join point]]s'' because they are points in a running program where additional behavior can be usefully joined. A join point needs to be addressable and understandable by an ordinary programmer to be useful. It should also be stable across inconsequential program changes to maintain aspect stability. Many AOP implementations support method executions and field references as join points. # A way to specify (or ''quantify'') join points, called ''[[pointcut]]s''. Pointcuts determine whether a given join point matches. Most useful pointcut languages use a syntax like the base language (for example, [[AspectJ]] uses Java signatures) and allow reuse through naming and combination. # A means of specifying code to run at a join point. [[AspectJ]] calls this ''[[advice in aspect-oriented programming|advice]]'', and can run it before, after, and around join points. Some implementations also support defining a method in an aspect on another class. Join-point models can be compared based on the join points exposed, how join points are specified, the operations permitted at the join points, and the structural enhancements that can be expressed. ===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, and exception handlers. They do not include loops, super calls, throws clauses, or multiple statements. | Pointcuts are specified by combinations of ''primitive pointcut designators'' (PCDs). "Kinded" PCDs match a particular kind of join point (e.g., method execution) and often take a Java-like signature as input. One such pointcut looks like this: <syntaxhighlight lang="aspectj"> execution(* set*(*)) </syntaxhighlight> 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, <syntaxhighlight lang="aspectj"> this(Point) </syntaxhighlight> 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: <syntaxhighlight lang="aspectj"> within(com.company.*) </syntaxhighlight> 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: <syntaxhighlight lang="aspectj"> pointcut set() : execution(* set*(*) ) && this(Point) && within(com.company.*); </syntaxhighlight> 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: <syntaxhighlight lang="aspectj"> after() : set() { Display.update(); } </syntaxhighlight> 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=== There are other kinds of JPMs. All advice languages can be defined in terms of their JPM. For example, a hypothetical aspect language for [[Unified Modeling Language|UML]] may have the following JPM: * Join points are all model elements. * Pointcuts are some [[Boolean expression]] combining the model elements. * The means of affect at these points are a visualization of all the matched join points. ===Inter-type declarations=== ''Inter-type declarations'' provide a way to express cross-cutting concerns affecting the structure of modules. Also known as ''open classes'' and ''[[extension method]]s'', this enables programmers to declare in one place members or parents of another class, typically to combine all the code related to a concern in one aspect. For example, if a programmer implemented the cross-cutting display-update concern using visitors, an inter-type declaration using the [[visitor pattern]] might look like this in AspectJ: <syntaxhighlight lang="aspectj"> aspect DisplayUpdate { void Point.acceptVisitor(Visitor v) { v.visit(this); } // other crosscutting code... } </syntaxhighlight> This code snippet adds the <code>acceptVisitor</code> method to the <code>Point</code> class. Any structural additions are required to be compatible with the original class, so that clients of the existing class continue to operate, unless the AOP implementation can expect to control all clients at all times.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)