Content deleted Content added
Bluelink 1 book for verifiability.) #IABot (v2.0) (GreenC bot |
m Undid revision 1305034158 by Bender the Bot (talk) bot error fixed |
||
(66 intermediate revisions by 48 users not shown) | |||
Line 1:
{{Short description|Programming
{{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
AOP includes programming methods and tools that support the modularization of concerns at the level of the source code, while
Aspect-oriented programming entails breaking down program logic into
[[
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
The examples in this article use AspectJ.
The [[Microsoft Transaction Server]] is considered to be the first major application of AOP followed by [[Enterprise JavaBeans]].<ref name="BoxSells2002">{{cite book|author1=Don Box|author2=Chris Sells|title=Essential.NET: The common language runtime|url=https://archive.org/details/essentialnetcomm01boxd|url-access=registration|
== Motivation and basic concepts ==
Typically, an aspect is ''scattered'' or ''tangled'' as code, making it harder to understand and maintain. It is scattered by
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>
<
void transfer(Account fromAcc, Account toAcc, int amount) throws Exception {
if (fromAcc.getBalance() < amount)
Line 32 ⟶ 33:
toAcc.deposit(amount);
}
</syntaxhighlight>
However, this transfer method overlooks certain considerations that a deployed application would require
A version with all those new concerns
<
void transfer(Account fromAcc, Account toAcc, int amount, User user,
Logger logger, Database database) throws Exception {
Line 60 ⟶ 61:
logger.info("Transaction successful.");
}
</syntaxhighlight>
In this example, other interests have become ''tangled'' with the basic functionality (sometimes called the ''business logic concern''). Transactions, security, and logging all exemplify
Now consider what
AOP
So for the example above implementing logging in an aspect:
<
aspect Logger {
void Bank.transfer(Account fromAcc, Account toAcc, int amount, User user, Logger logger) {
Line 82 ⟶ 83:
// Other crosscutting code.
}
</syntaxhighlight>
One can think of AOP as a debugging tool or
==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
# 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
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, exception handlers, etc. They do not include loops, super calls, throws clauses, multiple statements, etc.
<syntaxhighlight lang="aspectj">
▲* Pointcuts are specified by combinations of ''primitive pointcut designators'' (PCDs).
</syntaxhighlight>
▲:"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,
<syntaxhighlight lang="aspectj">
</syntaxhighlight>
"Scope" PCDs limit the lexical scope of the join point. For example:
<syntaxhighlight lang="aspectj">
</syntaxhighlight>
Pointcuts can be composed and named for reuse. For example:
<
</syntaxhighlight>
<syntaxhighlight lang="aspectj">
</syntaxhighlight>
▲ 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===
Line 137 ⟶ 139:
* Join points are all model elements.
* Pointcuts are some
* 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
<
aspect DisplayUpdate {
void Point.acceptVisitor(Visitor v) {
Line 150 ⟶ 152:
// other crosscutting code...
}
</syntaxhighlight>
This code snippet adds the <code>acceptVisitor</code> method to the <code>Point</code> class.
==Implementation==
Line 162 ⟶ 164:
# the ultimate interpreter or environment is updated to understand and implement AOP features.
The difficulty of changing environments means most implementations produce compatible combination programs through a
Systems can implement source-level weaving using preprocessors (as C++ was implemented originally in [[CFront]]) that require access to program source files. However, Java's well-defined binary form enables bytecode weavers to work with any Java program in .class-file form. Bytecode weavers can be deployed during the build process or, if the weave model is per-class, during class loading.
Any solution that combines programs at runtime
[[Deploy-time]] weaving offers another approach.<ref>{{cite web |url=http://www.forum2.org/tal/AspectJ2EE.pdf |title=Archived copy |
===Terminology===
Line 174 ⟶ 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,
== Adoption issues ==
Programmers need to be able to read
Even with proper education, understanding
Given the power of AOP,
==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
<
5 INPUT X
10 PRINT 'Result is :'
Line 202 ⟶ 206:
25 X = X * X
30 RETURN
</syntaxhighlight>
with an AOP fragment with analogous semantics:
<
main() {
input x
Line 214 ⟶ 218:
return temp * temp
}
</syntaxhighlight>
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]]
**[https://github.com/tfreyburger/aspectDN/ AspectDN] is an AOP implementation allowing to weave the aspects directly on the .NET executable files.
*[[
*[[
*[[AutoHotkey]]<ref>{{cite web|url=http://www.autohotkey.com/forum/viewtopic.php?p=243426|archive-url=https://archive.today/20130117125117/http://www.autohotkey.com/forum/viewtopic.php?p=243426|url-status=dead|archive-date=17 January 2013|title=Function Hooks|website=autohotkey.com|access-date=5 May 2018}}</ref>
*[[C (programming language)|C]] *[[COBOL]]<ref>{{cite web|url=http://homepages.vub.ac.be/~kdeschut/cobble/|title=Cobble
*The [[Cocoa (API)|Cocoa]] [[Objective-C]] frameworks<ref>{{cite web|url=http://www.ood.neu.edu/aspectcocoa/|title=AspectCocoa|website=neu.edu|
*[[ColdFusion]]<ref>{{cite web|url=http://coldspringframework.org/|title=ColdSpring Framework: Welcome|date=5 November 2005|
*[[Common Lisp]]<ref>{{cite web|url=http://common-lisp.net/project/closer/aspectl.html|title=Closer Project: AspectL.|
*[[
*[[Delphi Prism]]<ref>{{cite web|url=http://prismwiki.codegear.com/en/Cirrus|title=RemObjects Cirrus|website=codegear.com|
*[[E (verification language)|e]] (IEEE 1647)
*[[Emacs Lisp]]<ref>{{cite web|url=https://www.gnu.org/software/emacs/
*[[Groovy (programming language)|Groovy]]
*[[Haskell]]<ref>[[Monad (functional programming)|Monad]]s allow program semantics to be altered by changing the type of the program without altering its code: {{cite journal |citeseerx=10.1.1.25.8262 |title=Monads As a theoretical basis for AOP |journal=International Workshop on Aspect-Oriented Programming at ECOOP |first=Wolfgang |last=De Meuter |year=1997 |page=25}} {{cite book |chapter-url=http://dl.acm.org/citation.cfm?id=2451457 |first1=Nicolas |last1=Tabareau |first2=Ismael |last2=Figueroa |first3=Éric |last3=Tanter |title=Proceedings of the 12th annual international conference on Aspect-oriented software development |chapter=A typed monadic embedding of aspects |series=Aosd '13 |date=March 2013 |pages=171–184 |doi=10.1145/2451436.2451457 |isbn=9781450317665 |s2cid=27256161 |url=https://hal.inria.fr/hal-00763695/file/main.pdf}} [[Type class]]es allow additional capabilities to be added to a type: {{cite book |first1=Martin |last1=Sulzmann |first2=Meng |last2=Wang |title=Proceedings of the 6th workshop on Foundations of aspect-oriented languages |chapter=Aspect-oriented programming with type classes |chapter-url=http://portal.acm.org/citation.cfm?id=1233842 |date=March 2007 |pages=65–74 |doi=10.1145/1233833.1233842 |isbn=978-1595936615 |s2cid=3253858 |url=https://kar.kent.ac.uk/47468/1/local_143541.pdf}}.</ref>
*[[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|
*[[make (software)|make]]<ref>{{cite web|url=http://www.bramadams.org/makao/|archive-url=https://archive.
*[[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|
*[[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|
*[[UML 2|UML 2.0]]<ref>{{cite web|url=http://www.iit.edu/~concur/weavr|title=WEAVR|website=iit.edu|
*[[XML]]<ref>{{cite web|url=https://code.google.com/p/aspectxml/|title=aspectxml
==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 272 ⟶ 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 |year=2004 |title=Aspect-Oriented Software Development |publisher=Addison-Wesley |isbn=978-0-321-21976-3}}
* {{cite book |author1=
* {{cite book |first=Ramnivas |last=Laddad |author-link=Ramnivas Laddad |year=2003 |title=AspectJ in Action: Practical Aspect-Oriented Programming |publisher=Manning |isbn=978-1-930110-93-9 |url-access=registration |url=https://archive.org/details/aspectjinactionp00ladd}}
* {{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.''
* {{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|
* 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]
*
* [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 306 ⟶ 310:
* [http://java2novice.com/spring/aop-and-aspectj-introduction/ Spring AOP and AspectJ Introduction]
* [http://www.cs.bilkent.edu.tr/~bedir/CS586-AOSD AOSD Graduate Course at Bilkent University]
* [http://www.se-radio.net/podcast/2008-08/episode-106-introduction-aop Introduction to AOP
* [https://web.archive.org/web/20120801133941/http://innoli.com/en/Innoli-EN/OpenSource.html An Objective-C implementation of AOP by Szilveszter Molnar]
* [https://github.com/forensix/MGAOP Aspect-Oriented programming for iOS and OS X by Manuel Gebele]
* [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}}
|