Content deleted Content added
Jerryobject (talk | contribs) Small WP:COPYEDITs WP:EoS: clarify, WP:TERSE. WP:REFerence WP:CITation parameters: cut whitespace characters to standardize, aid work via small screens, conform to master templates. MOS:FIRSTABBReviations clarify, define before WP:ABBRs in parentheses. WP:LINKs: needless WP:PIPEs > WP:NOPIPEs, update-standardizes. Avoidable WP:SLASH > comma+space. Nonlead-word nonproper noun MOS:CAPS > WP:LOWERCASE sentence case. |
m Streamlined text and corrected grammar |
||
Line 6:
AOP includes programming methods and tools that support the modularization of concerns at the level of the source code, while '''aspect-oriented software development''' refers to a whole engineering discipline.
Aspect-oriented programming entails breaking down program logic into
[[Logging (computing)|Logging]] exemplifies a
All AOP implementations have some
==History==
Line 22:
== Motivation and basic concepts ==
Typically, an aspect is ''scattered'' or ''tangled'' as code, making it harder to understand and maintain. It is scattered by the function (such as logging) being spread over a number of unrelated functions that might use ''its'' function, possibly in entirely unrelated systems or written in different
For example, consider a banking application with a conceptually very simple method for transferring an amount from one account to another:<ref>Note: The examples in this article appear in a syntax that resembles that of the [[Java (programming language)|Java]] language.</ref>
Line 37:
However, this transfer method overlooks certain considerations that a deployed application would require, such as verifying that the current user is authorized to perform this operation, encapsulating [[database transaction|database transactions]] to prevent accidental data loss, and logging the operation for diagnostic purposes.
A version with all those new concerns
<syntaxhighlight lang="java">
Line 65:
In this example, other interests have become ''tangled'' with the basic functionality (sometimes called the ''business logic concern''). Transactions, security, and logging all exemplify ''[[cross-cutting concern]]s''.
Now consider what would happen if we suddenly need to change the security considerations for the application. In the program's current version, security-related operations appear ''scattered'' across numerous methods, and such a change would require
AOP
So for the example above implementing logging in an aspect:
Line 102:
| Pointcuts are specified by combinations of ''primitive pointcut designators'' (PCDs).
"Kinded" PCDs match a particular kind of join point (e.g., method execution) and
execution(* set*(*))
Line 143:
===Inter-type declarations===
''Inter-type declarations'' provide a way to express
<syntaxhighlight lang="aspectj">
Line 176:
Standard terminology used in Aspect-oriented programming may include:
;Cross-cutting concerns: {{main article|Cross-cutting concern}} Even though most classes in an
;
;
;Pointcut: {{main article|Pointcut}} This refers to the point of execution in the application at which cross-cutting concern needs to be applied. In our example, a pointcut is reached when the thread enters a method, and another pointcut is reached when the thread exits the method.
;
;Aspect: {{main article|Aspect (computer science)}} The combination of the pointcut and the advice is termed an aspect. In the example above, we add a logging aspect to our application by defining a pointcut and giving the correct advice.
== Comparison to other programming paradigms ==
Aspects emerged from [[object-oriented programming]] and [[reflective programming]]. AOP languages have functionality similar to, but more restricted than, [[Metaobject|metaobject protocols]]. Aspects relate closely to programming concepts like [[subjects (programming)|subjects]], [[mixin]]s, and [[delegation (programming)|delegation]]. Other ways to use aspect-oriented programming paradigms include [[Composition Filters]] and the [[Hyper/J|hyperslices]] approach. Since at least the 1970s, developers have been using forms of interception and dispatch-patching that resemble some of the implementation methods for AOP, but these never had the semantics that the
Designers have considered alternative ways to achieve separation of code, such as [[C Sharp (programming language)|C#]]'s partial types, but such approaches lack a quantification mechanism that allows reaching several join points of the code with one declarative statement.{{citation needed|date=May 2021}}
Though it may seem unrelated, in testing, the use of mocks or stubs requires the use of AOP techniques, such as around advice. Here the collaborating objects are for the purpose of the test, a cross
== Adoption issues ==
Programmers need to be able to read and understand code to prevent errors.<ref>[[Edsger Dijkstra]], [http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD249.PDF ''Notes on Structured Programming''] {{webarchive|url=https://web.archive.org/web/20061012020239/http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD249.PDF |date=2006-10-12}}, pg. 1-2</ref>
Even with proper education, understanding
Given the power of AOP, making a logical mistake in expressing
==Criticism==
Line 221 ⟶ 223:
General criticisms are that AOP purports to improve "both modularity and the structure of code", but some counter that it instead undermines these goals and impedes "independent development and understandability of programs".<ref name="steimann">{{Cite journal |doi=10.1145/1167515.1167514 |title=The paradoxical success of aspect-oriented programming |journal=ACM SIGPLAN Notices |volume=41 |issue=10 |pages=481–497 |year=2006 |last1=Steimann |first1=F. |citeseerx=10.1.1.457.2210}}, ([http://people.dsv.su.se/~johano/ioor/succ_aop.pdf slides] {{webarchive|url=https://web.archive.org/web/20160304060007/http://people.dsv.su.se/~johano/ioor/succ_aop.pdf |date=2016-03-04}},[http://www.eecs.ucf.edu/~leavens/modular-aop/Discussion.pdf slides 2] {{webarchive|url=https://web.archive.org/web/20150923234021/http://www.eecs.ucf.edu/~leavens/modular-aop/Discussion.pdf |date=2015-09-23}}, [http://www.oopsla.org/2006/submission/essays/the_paradoxical_success_of_aspect-oriented_programming.html abstract] {{webarchive|url=https://web.archive.org/web/20150924060711/http://www.oopsla.org/2006/submission/essays/the_paradoxical_success_of_aspect-oriented_programming.html |date=2015-09-24}}), Friedrich Steimann, Gary T. Leavens, [[OOPSLA]] 2006</ref> Specifically, quantification by pointcuts breaks modularity: "one must, in general, have whole-program knowledge to reason about the dynamic execution of an aspect-oriented program."<ref>{{cite web|url=http://www.eecs.ucf.edu/~leavens/modular-aop/|title=More Modular Reasoning for Aspect-Oriented Programs|access-date=11 August 2015|url-status=live|archive-url=https://web.archive.org/web/20150812045258/http://www.eecs.ucf.edu/~leavens/modular-aop/|archive-date=12 August 2015}}</ref> Further, while its goals (modularizing cross-cutting concerns) are well understood, its actual definition is unclear and not clearly distinguished from other well-established techniques.<ref name="steimann"/> Cross-cutting concerns potentially cross-cut each other, requiring some resolution mechanism, such as ordering.<ref name="steimann"/> Indeed, aspects can apply to themselves, leading to problems such as the [[liar paradox]].<ref>{{cite web|url=http://www.fernuni-hagen.de/ps/pubs/FOAL2006.pdf|title=AOP and the Antinomy of the Liar|website=fernuni-hagen.de|access-date=5 May 2018|url-status=live|archive-url=https://web.archive.org/web/20170809201001/http://www.fernuni-hagen.de/ps/pubs/FOAL2006.pdf|archive-date=9 August 2017}}</ref>
Technical criticisms include that the quantification of pointcuts (defining where advices are executed) is "extremely sensitive to changes in the program", which is known as the ''fragile pointcut problem''.<ref name="steimann"/> The problems with pointcuts are deemed intractable
==Implementations==
|