Content deleted Content added
No edit summary |
m Undid revision 1305034158 by Bender the Bot (talk) bot error fixed |
||
(14 intermediate revisions by 14 users not shown) | |||
Line 1:
{{
{{Programming paradigms}}▼
{{Use dmy dates|date=June 2023}}
In [[computing]], '''aspect-oriented programming''' ('''AOP''') is a [[programming paradigm]] that aims to increase [[Modularity (programming)|modularity]] by allowing the [[separation of concerns|separation of]] [[cross-cutting concern]]s. It does so by adding behavior to existing code (an [[Advice (programming)|advice]]) ''without'' modifying the code
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==
AOP has several direct antecedents A1 and A2:<ref>{{Cite conference |
[[Gregor Kiczales]] and colleagues at [[Xerox PARC]] developed the explicit concept of AOP and followed this with the [[AspectJ]] AOP extension to Java. IBM's research team pursued a tool approach over a language design approach and in 2001 proposed [[Hyper/J]] and the [[Concern Manipulation Environment]], which have not seen wide
The examples in this article use AspectJ.
Line 23 ⟶ 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 38 ⟶ 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 66 ⟶ 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 98 ⟶ 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, 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
<syntaxhighlight lang="aspectj">
</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">
</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">
</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">
</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>".
Line 129 ⟶ 128:
| 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">
</syntaxhighlight>
Line 144 ⟶ 143:
===Inter-type declarations===
''Inter-type declarations'' provide a way to express
<syntaxhighlight lang="aspectj">
Line 171 ⟶ 170:
Any solution that combines programs at runtime must provide views that segregate them properly to maintain the programmer's segregated model. Java's bytecode support for multiple source files enables any debugger to step through a properly woven .class file in a source editor. However, some third-party decompilers cannot process woven code because they expect code produced by Javac rather than all supported bytecode forms (see also [[#Criticism|§ Criticism]], below).
[[Deploy-time]] weaving offers another approach.<ref>{{cite web |url=http://www.forum2.org/tal/AspectJ2EE.pdf |title=Archived copy |access-date=2005-06-19 |url-status=dead |archive-url=https://web.archive.org/web/20051008065854/http://www.forum2.org/tal/AspectJ2EE.pdf |archive-date=2005-10-08
===Terminology===
Line 177 ⟶ 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 [[
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
Even with proper education, understanding
Given the power of AOP, making a logical mistake in expressing
==Criticism==
The most basic criticism of the effect of AOP is that control flow is obscured, and that it is not only worse than the much-maligned [[GOTO]] statement, but is closely analogous to the joke [[COME FROM]] statement.<ref name="harmful"
<syntaxhighlight lang="basic" highlight="4">
5 INPUT X
Line 220 ⟶ 221:
Indeed, the pointcut may depend on runtime condition and thus not be statically deterministic. This can be mitigated but not solved by static analysis and IDE support showing which advices ''potentially'' match.
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 |
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==
*[[.NET
[https://github.com/vc3/Afterthought Afterthought] {{webarchive|url=https://web.archive.org/web/20160315162029/https://github.com/vc3/Afterthought |date=2016-03-15
**[https://www.postsharp.net/ PostSharp] is a commercial AOP implementation with a free but limited edition.
**[[Unity Application Block|Unity]] provides an API to facilitate proven practices in core areas of programming including data access, security, logging, exception handling and others.
**[https://github.com/tfreyburger/aspectDN/ AspectDN] is an AOP implementation allowing to weave the aspects directly on the .
*[[ActionScript]]<ref>{{cite web|url=http://www.as3commons.org/as3-commons-bytecode|title=Welcome to as3-commons-bytecode|website=as3commons.org|access-date=5 May 2018|url-status=live|archive-url=https://web.archive.org/web/20141003100345/http://www.as3commons.org/as3-commons-bytecode/|archive-date=3 October 2014}}</ref>
*[[Ada (programming language)|Ada]]<ref>{{cite web|url=http://www.adacore.com/uploads/technical-papers/Ada2012_Rational_Introducion.pdf|title=Ada2012 Rationale|website=adacore.com|access-date=5 May 2018|url-status=live|archive-url=https://web.archive.org/web/20160418132340/http://www.adacore.com/uploads/technical-papers/Ada2012_Rational_Introducion.pdf|archive-date=18 April 2016}}</ref>
*[[AutoHotkey]]<ref>{{cite web|url=http://www.autohotkey.com/forum/viewtopic.php?p=243426|archive-url=https://archive.today/
*[[C (programming language)|C]]
*[[COBOL]]<ref>{{cite web|url=http://homepages.vub.ac.be/~kdeschut/cobble/|title=Cobble|website=vub.ac.be|access-date=5 May 2018}}{{dead link|date=May 2018 |bot=SheriffIsInTown |fix-attempted=yes
*The [[Cocoa (API)|Cocoa]] [[Objective-C]] frameworks<ref>{{cite web|url=http://www.ood.neu.edu/aspectcocoa/|title=AspectCocoa|website=neu.edu|access-date=5 May 2018|url-status=dead|archive-url=https://web.archive.org/web/20071026022525/http://www.ood.neu.edu/aspectcocoa/|archive-date=26 October 2007}}</ref>
*[[ColdFusion]]<ref>{{cite web|url=http://coldspringframework.org/|title=ColdSpring Framework: Welcome|date=5 November 2005|access-date=5 May 2018|url-status=bot: unknown|archive-url=https://web.archive.org/web/20051105014513/http://coldspringframework.org/|archive-date=5 November 2005}}</ref>
*[[Common Lisp]]<ref>{{cite web|url=http://common-lisp.net/project/closer/aspectl.html|title=Closer Project: AspectL.|access-date=11 August 2015|url-status=live|archive-url=http://archive.wikiwix.com/cache/20110223172923/http://common-lisp.net/project/closer/aspectl.html|archive-date=23 February 2011}}</ref>
*[[Delphi (
*[[Delphi Prism]]<ref>{{cite web|url=http://prismwiki.codegear.com/en/Cirrus|title=RemObjects Cirrus|website=codegear.com|access-date=5 May 2018|url-status=dead|archive-url=https://web.archive.org/web/20120123094027/http://prismwiki.codegear.com/en/Cirrus|archive-date=23 January 2012}}</ref>
*[[E (verification language)|e]] (IEEE 1647)
*[[Emacs Lisp]]<ref>{{cite web|url=https://www.gnu.org/software/emacs/manual/html_node/elisp/Advising-Functions.html|title=Emacs Advice Functions|publisher=GNU Project|access-date=5 May 2018|url-status=live|archive-url=https://web.archive.org/web/20111024211408/http://www.gnu.org/software/emacs/elisp/html_node/Advising-Functions.html|archive-date=24 October 2011}}</ref>
*[[Groovy (programming language)|Groovy]]
*[[
*[[Java (programming language)|Java]]<ref>Numerous others: [http://www.caesarj.org/ CaesarJ] {{webarchive|url=https://web.archive.org/web/20081219181529/http://caesarj.org/ |date=2008-12-19
**[[AspectJ]]
*[[JavaScript]]<ref>Many: [http://i.gotfresh.info/2007/12/7/advised-methods-for-javascript-with-prototype/ Advisable] {{webarchive|url=https://web.archive.org/web/20080704052200/http://i.gotfresh.info/2007/12/7/advised-methods-for-javascript-with-prototype |date=2008-07-04
*[[Logtalk (programming language)|Logtalk]]<ref>Using built-in support for categories (which allows the encapsulation of aspect code) and event-driven programming (which allows the definition of ''before'' and after ''event'' handlers).</ref>
*[[Lua (programming language)|Lua]]<ref>{{cite web|url=http://luaforge.net/projects/aspectlua/|title=AspectLua|access-date=11 August 2015|url-status=live|archive-url=https://web.archive.org/web/20150717094121/http://luaforge.net/projects/aspectlua/|archive-date=17 July 2015}}</ref>
*[[make (software)|make]]<ref>{{cite web|url=http://www.bramadams.org/makao/|archive-url=https://archive.today/
*[[Matlab]]<ref>{{cite web|url=http://www.sable.mcgill.ca/mclab/aspectmatlab/
*[[ML (programming language)|ML]]<ref>{{cite web |title=AspectML – Aspect-oriented Functional Programming Language Research |url=http://www.cs.princeton.edu/sip/projects/aspectml/
*[[Nemerle]]<ref>{{cite web|url=https://github.com/rsdn/nemerle/blob/master/README.md|title=nemerle/README.md at master · rsdn/nemerle|website=[[GitHub]] |access-date=22 March 2018}}</ref>
*[[Perl]]<ref>{{cite web|url=https://metacpan.org/module/Aspect|title=Aspect – Aspect-Oriented Programming (AOP) for Perl – metacpan.org|author=Adam Kennedy|access-date=11 August 2015|url-status=live|archive-url=https://web.archive.org/web/20130831064935/https://metacpan.org/module/Aspect|archive-date=31 August 2013}}</ref>
*[[PHP]]<ref>Several: [http://aop.io PHP-AOP (AOP.io)] {{webarchive|url=http://archive.wikiwix.com/cache/20140818050736/http://aop.io/ |date=2014-08-18
*[[Prolog]]<ref>{{cite web |date=14 December 2005 |title=Aspect-Oriented Programming in Prolog |url=http://www.bigzaphod.org/whirl/dma/docs/aspects/aspects-man.html
*[[Python (programming language)|Python]]<ref>Several: [http://peak.telecommunity.com/ PEAK] {{webarchive|url=https://web.archive.org/web/20050409082546/http://peak.telecommunity.com/ |date=2005-04-09
*[[Racket (programming language)|Racket]]<ref>{{cite web|url=http://planet.racket-lang.org/display.ss?package=aspectscheme.plt&owner=dutchyn|title=PLaneT Package Repository : PLaneT > dutchyn > aspectscheme.plt|access-date=11 August 2015|url-status=live|archive-url=https://web.archive.org/web/20150905062740/http://planet.racket-lang.org/display.ss?package=aspectscheme.plt&owner=dutchyn|archive-date=5 September 2015}}</ref>
*[[Ruby (programming language)|Ruby]]<ref>{{cite web|url=
*[[Squeak]] [[Smalltalk]]<ref>{{cite web|url=http://www.prakinf.tu-ilmenau.de/~hirsch/Projects/Squeak/AspectS/|title=AspectS|website=tu-ilmenau.de|access-date=5 May 2018|url-status=dead|archive-url=https://web.archive.org/web/20060106112030/http://www.prakinf.tu-ilmenau.de/~hirsch/Projects/Squeak/AspectS/|archive-date=6 January 2006}}</ref><ref>{{cite web|url=http://csl.ensm-douai.fr/MetaclassTalk|title=MetaclassTalk: Reflection and Meta-Programming in Smalltalk|access-date=11 August 2015|url-status=dead|archive-url=https://web.archive.org/web/20150729062351/http://csl.ensm-douai.fr/MetaclassTalk|archive-date=29 July 2015}}</ref>
*[[UML 2|UML 2.0]]<ref>{{cite web|url=http://www.iit.edu/~concur/weavr|title=WEAVR|website=iit.edu|access-date=5 May 2018|url-status=live|archive-url=https://web.archive.org/web/20081212200221/http://www.iit.edu/~concur/weavr/|archive-date=12 December 2008}}</ref>
Line 266 ⟶ 267:
==See also==
* [[Distributed AOP]]
* [[Attribute grammar]], a formalism that can be used for aspect-oriented programming on
* [[Programming paradigm]]s
* [[Subject-oriented programming]], an alternative to
* [[Role-oriented programming]], an alternative to
* [[Predicate dispatch]], an older alternative to
* [[Executable UML]]
* [[Decorator pattern]]
Line 276 ⟶ 277:
==Notes and references==
{{
==Further reading==
* {{Cite conference |
* {{cite book |author1=Robert E. Filman |author2=Tzilla Elrad |author3=Siobhán Clarke |author3-link=Siobhán Clarke|author4=Mehmet Aksit |
* {{cite book |author1=Renaud Pawlak, Lionel Seinturier
* {{cite book |
* {{cite book |
* [http://www.cmsdevelopment.com/en/articles/aosdinphp/ Aspect-oriented Software Development and PHP, Dmitry Sheiko, 2006]
* {{cite book |author1=Siobhán Clarke|author1-link=Siobhán Clarke |author2=Elisa Baniassad
* {{cite book |author
* "Adaptive Object-Oriented Programming Using Graph-Based Customization" – Lieberherr, Silva-Lepe, ''et al.'' – 1994
* {{cite journal|last=Zambrano Polo y La Borda|first=Arturo Federico|title=Addressing aspect interactions in an industrial setting: experiences, problems and solutions|date=5 June 2013|pages=159|doi=10.35537/10915/35861|url=http://sedici.unlp.edu.ar/handle/10915/35861|access-date=30 May 2014|doi-access=free}}
* Wijesuriya, Viraj Brian (2016-08-30) ''[http://www.slideshare.net/tyrantbrian/aspect-oriented-development Aspect Oriented Development, Lecture Notes, University of Colombo School of Computing, Sri Lanka]''
* {{
== External links ==
* [[Eric Bodden]]'s [http://www.sable.mcgill.ca/aop.net/ list of AOP tools] in .
* [https://web.archive.org/web/20030821074213/http://aosd.net/conference/ Aspect-Oriented Software Development], annual conference on AOP
* [http://www.eclipse.org/aspectj/doc/released/progguide/
* [https://web.archive.org/web/20141216200424/http://aspectbench.org/ The AspectBench Compiler for AspectJ], another Java implementation
* [http://www.ibm.com/developerworks/views/java/libraryview.jsp?search_by=AOP@work: Series of IBM developerWorks articles on AOP]
Line 301 ⟶ 302:
* [https://web.archive.org/web/20090821185951/http://codefez.com/what-is-aspect-oriented-programming/ What is Aspect-Oriented Programming?], introduction with RemObjects Taco
* [http://www.cis.uab.edu/gray/Research/C-SAW/ Constraint-Specification Aspect Weaver]
* [http://www.devx.com/Java/Article/28422 Aspect- vs. Object-Oriented Programming: Which Technique, When?] {{Webarchive|url=https://web.archive.org/web/20210415064448/http://www.devx.com/Java/Article/28422 |date=15 April 2021
* [http://video.google.com/videoplay?docid=8566923311315412414&q=engEDU Gregor Kiczales, Professor of Computer Science, explaining AOP], video 57 min.
* [http://database.ittoolbox.com/documents/academic-articles/what-does-aspectoriented-programming-mean-to-cobol-4570 Aspect Oriented Programming in COBOL] {{Webarchive|url=https://web.archive.org/web/20081217055353/http://database.ittoolbox.com/documents/academic-articles/what-does-aspectoriented-programming-mean-to-cobol-4570 |date=2008-12-17
* [http://static.springframework.org/spring/docs/2.0.x/reference/aop.html Aspect-Oriented Programming in Java with Spring Framework]
* [http://www.sharpcrafters.com/aop.net Wiki dedicated to AOP methods on.NET]
Line 314 ⟶ 315:
* [https://community.devexpress.com/blogs/wpf/archive/2013/12/04/devexpress-mvvm-framework-introduction-to-poco-viewmodels.aspx DevExpress MVVM Framework. Introduction to POCO ViewModels]
{{aosd}}
▲{{Programming paradigms navbox}}
{{Authority control}}
|