Content deleted Content added
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.8) (AManWithNoPlan - 7485 |
m Undid revision 1305034158 by Bender the Bot (talk) bot error fixed |
||
(41 intermediate revisions by 33 users not shown) | |||
Line 1:
{{
{{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
{{Programming paradigms}}▼
AOP includes programming methods and tools that support the modularization of concerns at the level of the source code, while
▲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 additional behavior to existing code (an [[Advice (programming)|advice]]) ''without'' modifying the code itself, instead separately specifying which code is modified via a "[[pointcut]]" specification, such as "log all function calls when the function's name begins with 'set{{'"}}. This allows behaviors that are not central to the [[business logic]] (such as logging) to be added to a program without cluttering the code core to the functionality. AOP forms a basis for [[aspect-oriented software development]].
Aspect-oriented programming entails breaking down program logic into
▲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 distinct parts (so-called ''concerns'', cohesive areas of functionality). Nearly all programming paradigms support some level of grouping and [[encapsulation (computer science)|encapsulation]] of concerns into separate, independent entities by providing abstractions (e.g., functions, procedures, modules, classes, methods) that can be used for implementing, abstracting and composing these concerns. Some concerns "cut across" multiple abstractions in a program, and defy these forms of implementation. These concerns are called ''cross-cutting concerns'' or horizontal concerns.
All AOP implementations have some
▲[[data logging|Logging]] exemplifies a crosscutting concern because a logging strategy necessarily affects every logged part of the system. Logging thereby ''crosscuts'' all logged classes and methods.
▲All AOP implementations have some crosscutting expressions that encapsulate each concern in one place. The difference between implementations lies in the power, safety, and usability of the constructs provided. For example, interceptors that specify the methods to express a limited form of crosscutting, without much support for type-safety or debugging. [[AspectJ]] has a number of such expressions and encapsulates them in a special class, an [[aspect (computer science)|aspect]]. For example, an aspect can alter the behavior of the base code (the non-aspect part of a program) by applying [[Advice in aspect-oriented programming|advice]] (additional behavior) at various [[join point]]s (points in a program) specified in a quantification or query called a [[pointcut]] (that detects whether a given join point matches). An aspect can also make binary-compatible structural changes to other classes, like adding members or parents.
==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.
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
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 36 ⟶ 35:
</syntaxhighlight>
However, this transfer method overlooks certain considerations that a deployed application would require
A version with all those new concerns
<syntaxhighlight lang="java">
Line 64 ⟶ 63:
</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:
Line 86 ⟶ 85:
</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, and exception handlers
| 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>".
| 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>
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."}}
Line 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
<syntaxhighlight lang="aspectj">
Line 156:
This code snippet adds the <code>acceptVisitor</code> method to the <code>Point</code> class.
==Implementation==
Line 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 type of [[program transformation]] known as ''weaving''. An [[aspect weaver]] reads the aspect-oriented code and generates appropriate object-oriented code with the aspects integrated. The same AOP language can be implemented through a variety of weaving methods, so the semantics of a language should never be understood in terms of the weaving implementation. Only the speed of an implementation and its ease of deployment are affected by
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. [[AspectJ]] started with source-level weaving in 2001, delivered a per-class bytecode weaver in 2002, and offered advanced load-time support after the integration of [[AspectWerkz]] in 2005.
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 |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 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
<syntaxhighlight lang="basic" highlight="4">
5 INPUT X
Line 219 ⟶ 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 .NET executable files.
*[[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.
*[[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 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/
*[[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.
*[[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 *[[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>
*[[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 274 ⟶ 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|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]
* {{cite web |last1=Laddad |first1=Ramnivas |date=2002-01-18
* [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 308 ⟶ 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}}
|