Aspect-oriented programming
Encyclopedia
In computing
, aspect-oriented programming (AOP) is a programming paradigm
which aims to increase modularity
by allowing the separation of
cross-cutting concern
s. AOP forms a basis for aspect-oriented software development
.
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.
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 intercept 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
. For example, an aspect can alter the behavior of the base code (the non-aspect part of a program) by applying 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.
, subject-oriented programming
, Composition Filters and Adaptive Programming.
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 usage. EmacsLisp changelog added AOP related code in version 19.28. The examples in this article use AspectJ
as it is the most widely known AOP language.
The Microsoft Transaction Server
is considered to be the first major application of AOP followed by Enterprise JavaBean
.
For example, consider a banking application with a conceptually very simple method for transferring an amount from one account to another:
However, this transfer method overlooks certain considerations that a deployed application would require. It lacks security checks to verify that the current user has the authorization to perform this operation. A database transaction
should encapsulate the operation in order to prevent accidental data loss. For diagnostics, the operation should be logged to the system log. And so on. A simplified version with all those new concerns would look somewhat like this:
In the previous example other interests have become tangled with the basic functionality (sometimes called the business logic concern). Transactions, security, and logging all exemplify cross-cutting concerns.
Now consider what happens if we suddenly need to change (for example) 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 a major effort.
AOP attempts to solve this problem by allowing the programmer to express cross-cutting concerns in stand-alone modules called aspects. Aspects can contain advice (code joined to specified points in the program) and inter-type declarations (structural members added to other classes). For example, a security module can include advice that performs a security check before accessing a bank account. The pointcut
defines the times (join point
s) when one can access a bank account, and the code in the advice body defines how the security check is implemented. That way, both the check and the places can be maintained in one place. Further, a good pointcut can anticipate later program changes, so if another developer creates a new method to access the bank account, the advice will apply to the new method when it executes.
So for the above example implementing logging in an aspect:
One can think of AOP as a debugging tool or as a user-level tool. Advice should be reserved for the cases where you cannot get the function changed (user level) or do not want to change the function in production code (debugging).
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.
execution(* set*(*))
"Dynamic" PCDs check runtime types and bind variables. For example
this(Point)
"Scope" PCDs limit the lexical scope of the join point. For example:
within(com.company.*)
Pointcuts can be composed and named for reuse. For example
pointcut set : execution(* set*(*) ) && this(Point) && within(com.company.*);
after : set {
Display.update;
}
may have the following JPM:
might look like this in AspectJ:
This code snippet adds the
It is a requirement that any structural additions 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.
The difficulty of changing environments means most implementations produce compatible combination programs through a process known as weaving - a special case of program transformation
. 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 which method of combination is used.
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 has to 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 "Problems", below).
Deploy-time weaving offers another approach. This basically implies post-processing, but rather than patching the generated code, this weaving approach subclasses existing classes so that the modifications are introduced by method-overriding. The existing classes remain untouched, even at runtime, and all existing tools (debuggers, profilers, etc.) can be used during development. A similar approach has already proven itself in the implementation of many Java EE application servers, such as IBM
's WebSphere
.
and computational reflection. AOP languages have functionality similar to, but more restricted than metaobject protocols
. Aspects relate closely to programming concepts like subjects
, mixin
s, and delegation
. Other ways to use aspect-oriented programming paradigms include Composition Filters and the 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 crosscutting specifications provide written in one place.
Designers have considered alternative ways to achieve separation of code, such as C#'s partial types, but such approaches lack a quantification mechanism that allows reaching several join points of the code with one declarative statement.
Even with proper education, understanding crosscutting concerns can be difficult without proper support for visualizing both static structure and the dynamic flow of a program. Beginning in 2002, AspectJ began to provide IDE plug-ins to support the visualizing of crosscutting concerns. Those features, as well as aspect code assist and refactoring are now common.
Given the power of AOP, if a programmer makes a logical mistake in expressing crosscutting, it can lead to widespread program failure. Conversely, another programmer may change the join points in a program – e.g., by renaming or moving methods – in ways that the aspect writer did not anticipate, with unintended consequence
s. One advantage of modularizing crosscutting concerns is enabling one programmer to affect the entire system easily; as a result, such problems present as a conflict over responsibility between two or more developers for a given failure. However, the solution for these problems can be much easier in the presence of AOP, since only the aspect need be changed, whereas the corresponding problems without AOP can be much more spread out.
s have implemented AOP, within the language, or as an external library:
Computing
Computing is usually defined as the activity of using and improving computer hardware and software. It is the computer-specific part of information technology...
, aspect-oriented programming (AOP) is a programming paradigm
Programming paradigm
A programming paradigm is a fundamental style of computer programming. Paradigms differ in the concepts and abstractions used to represent the elements of a program and the steps that compose a computation A programming paradigm is a fundamental style of computer programming. (Compare with a...
which aims to increase modularity
Modularity (programming)
Modular programming is a software design technique that increases the extent to which software is composed of separate, interchangeable components called modules by breaking down program functions into modules, each of which accomplishes one function and contains everything necessary to accomplish...
by allowing the separation of
Separation of concerns
In computer science, separation of concerns is the process of separating a computer program into distinct features that overlap in functionality as little as possible. A concern is any piece of interest or focus in a program. Typically, concerns are synonymous with features or behaviors...
cross-cutting concern
Cross-cutting concern
In computer science, cross-cutting concerns are aspects of a program which affect other concerns.These concerns often cannot be cleanly decomposed from the rest of the system in both the design and implementation, and can result in either scattering , tangling , or both.For instance, if writing an...
s. AOP forms a basis for aspect-oriented software development
Aspect-oriented software development
In computing, Aspect-oriented software development is an emerging software development technology that seeks new modularizations of software systems in order to isolate secondary or supporting functions from the main program's business logic...
.
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.
Overview
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 of concerns into separate, independent entities by providing abstractions (e.g., procedures, modules, classes, methods) that can be used for implementing, abstracting and composing these concerns. But some concerns defy these forms of implementation and are called crosscutting concerns because they "cut across" multiple abstractions in a program.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 intercept express a limited form of crosscutting, without much support for type-safety or debugging. AspectJ
AspectJ
AspectJ is an aspect-oriented extension created at PARC for the Java programming language. It is available in Eclipse Foundation open-source projects, both stand-alone and integrated into Eclipse. AspectJ has become the widely-used de-facto standard for AOP by emphasizing simplicity and usability...
has a number of such expressions and encapsulates them in a special class, an aspect
Aspect (computer science)
In computer science, an aspect of a program is a feature linked to many other parts of the program, but which is not related to the program's primary function. An aspect crosscuts the program's core concerns, therefore violating its separation of concerns that tries to encapsulate unrelated functions...
. For example, an aspect can alter the behavior of the base code (the non-aspect part of a program) by applying advice
Advice in aspect-oriented programming
In aspect and functional programming, advice describes a class of functions which modify other functions when the latter are run; it is a certain function, method or procedure that is to be applied at a given join point of a program....
(additional behavior) at various join point
Join point
In computer science, a join point is a point in the control flow of a program. In aspect-oriented programming a set of join points is described as a pointcut...
s (points in a program) specified in a quantification or query called a pointcut
Pointcut
In aspect-oriented computer programming, a pointcut is a set of join points. Whenever the program execution reaches one of the join points described in the pointcut, a piece of code associated with the pointcut is executed. This allows a programmer to describe where and when additional code...
(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: reflection and metaobject protocolsMetaobject
In computer science, a metaobject or meta-object is any entity that manipulates, creates, describes, or implements other objects. The object that the metaobject is about is called the base object...
, subject-oriented programming
Subject-oriented programming
In computing, Subject-Oriented Programming is an object-oriented software paradigm in which the state and behavior of objects are not seen as intrinsic to the objects themselves, but are provided by various subjective perceptions of the objects...
, Composition Filters and Adaptive Programming.
Gregor Kiczales
Gregor Kiczales
Gregor Kiczales is a professor of computer science at the University of British Columbia in Canada. His best known work is on Aspect-oriented programming and the AspectJ extension for Java at Xerox PARC. He has also contributed to the design of the Common Lisp Object System, and is the author of...
and colleagues at Xerox PARC
Xerox PARC
PARC , formerly Xerox PARC, is a research and co-development company in Palo Alto, California, with a distinguished reputation for its contributions to information technology and hardware systems....
developed the explicit concept of AOP, and followed this with the AspectJ
AspectJ
AspectJ is an aspect-oriented extension created at PARC for the Java programming language. It is available in Eclipse Foundation open-source projects, both stand-alone and integrated into Eclipse. AspectJ has become the widely-used de-facto standard for AOP by emphasizing simplicity and usability...
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 usage. EmacsLisp changelog added AOP related code in version 19.28. The examples in this article use AspectJ
AspectJ
AspectJ is an aspect-oriented extension created at PARC for the Java programming language. It is available in Eclipse Foundation open-source projects, both stand-alone and integrated into Eclipse. AspectJ has become the widely-used de-facto standard for AOP by emphasizing simplicity and usability...
as it is the most widely known AOP language.
The Microsoft Transaction Server
Microsoft Transaction Server
Microsoft Transaction Server was software that provided services to Component Object Model software components, to make it easier to create large distributed applications. The major services provided by MTS were automated transaction management, instance management and role-based security...
is considered to be the first major application of AOP followed by Enterprise JavaBean
Enterprise JavaBean
Enterprise JavaBeans is a managed, server-side component architecture for modular construction of enterprise applications.The EJB specification is one of several Java APIs in the Java EE specification. EJB is a server-side model that encapsulates the business logic of an application...
.
Motivation and basic concepts
Typically, an aspect is scattered or tangled as code, making it harder to understand and maintain. It is scattered by virtue of the function (such as logging) being spread over a number of unrelated functions that might use its function, possibly in entirely unrelated systems, different source languages, etc. That means to change logging can require modifying all affected modules. Aspects become tangled not only with the mainline function of the systems in which they are expressed but also with each other. That means changing one concern entails understanding all the tangled concerns or having some means by which the effect of changes can be inferred.For example, consider a banking application with a conceptually very simple method for transferring an amount from one account to another:
However, this transfer method overlooks certain considerations that a deployed application would require. It lacks security checks to verify that the current user has the authorization to perform this operation. A database transaction
Database transaction
A transaction comprises a unit of work performed within a database management system against a database, and treated in a coherent and reliable way independent of other transactions...
should encapsulate the operation in order to prevent accidental data loss. For diagnostics, the operation should be logged to the system log. And so on. A simplified version with all those new concerns would look somewhat like this:
In the previous example other interests have become tangled with the basic functionality (sometimes called the business logic concern). Transactions, security, and logging all exemplify cross-cutting concerns.
Now consider what happens if we suddenly need to change (for example) 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 a major effort.
AOP attempts to solve this problem by allowing the programmer to express cross-cutting concerns in stand-alone modules called aspects. Aspects can contain advice (code joined to specified points in the program) and inter-type declarations (structural members added to other classes). For example, a security module can include advice that performs a security check before accessing a bank account. The pointcut
Pointcut
In aspect-oriented computer programming, a pointcut is a set of join points. Whenever the program execution reaches one of the join points described in the pointcut, a piece of code associated with the pointcut is executed. This allows a programmer to describe where and when additional code...
defines the times (join point
Join point
In computer science, a join point is a point in the control flow of a program. In aspect-oriented programming a set of join points is described as a pointcut...
s) when one can access a bank account, and the code in the advice body defines how the security check is implemented. That way, both the check and the places can be maintained in one place. Further, a good pointcut can anticipate later program changes, so if another developer creates a new method to access the bank account, the advice will apply to the new method when it executes.
So for the above example implementing logging in an aspect:
One can think of AOP as a debugging tool or as a user-level tool. Advice should be reserved for the cases where you cannot get the function changed (user level) or do not want to change the function in production code (debugging).
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 pointJoin pointIn computer science, a join point is a point in the control flow of a program. In aspect-oriented programming a set of join points is described as a pointcut...
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 in order for an aspect to be stable across such changes. Many AOP implementations support method executions and field references as join points. - A way to specify (or quantify) join points, called pointcutPointcutIn aspect-oriented computer programming, a pointcut is a set of join points. Whenever the program execution reaches one of the join points described in the pointcut, a piece of code associated with the pointcut is executed. This allows a programmer to describe where and when additional code...
s. Pointcuts determine whether a given join point matches. Most useful pointcut languages use a syntax like the base language (for example, AspectJAspectJAspectJ is an aspect-oriented extension created at PARC for the Java programming language. It is available in Eclipse Foundation open-source projects, both stand-alone and integrated into Eclipse. AspectJ has become the widely-used de-facto standard for AOP by emphasizing simplicity and usability...
uses Java signatures) and allow reuse through naming and combination. - A means of specifying code to run at a join point. AspectJAspectJAspectJ is an aspect-oriented extension created at PARC for the Java programming language. It is available in Eclipse Foundation open-source projects, both stand-alone and integrated into Eclipse. AspectJ has become the widely-used de-facto standard for AOP by emphasizing simplicity and usability...
calls this adviceAdvice in aspect-oriented programmingIn aspect and functional programming, advice describes a class of functions which modify other functions when the latter are run; it is a certain function, method or procedure that is to be applied at a given join point of a program....
, and can run it before, after, and around join points. Some implementations also support things like 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
- 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.
- Pointcuts are specified by combinations of primitive pointcut designators (PCDs).
- "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 "
set
" and there is exactly one argument of any type.
"Dynamic" PCDs check runtime types and bind variables. For example
this(Point)
- This pointcut matches when the currently-executing object is an instance of class
Point
. 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:
within(com.company.*)
- This pointcut matches any join point in any type in the
com.company
package. The*
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
pointcut set : execution(* set*(*) ) && this(Point) && within(com.company.*);
- This pointcut matches a method-execution join point, if the method name starts with "
set
" andthis
is an instance of typePoint
in thecom.company
package. It can be referred to using the name "set
".
- 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:
after : set {
Display.update;
}
- This effectively specifies: "if the
set
pointcut matches the join point, run the codeDisplay.update
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 UMLUnified Modeling Language
Unified Modeling Language is a standardized general-purpose modeling language in the field of object-oriented software engineering. The standard is managed, and was created, by the Object Management Group...
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 crosscutting concerns affecting the structure of modules. Also known as open classes, this enables programmers to declare in one place members or parents of another class, typically in order to combine all the code related to a concern in one aspect. For example, if a programmer implemented the crosscutting display-update concern using visitors instead, an inter-type declaration using the visitor patternVisitor pattern
In object-oriented programming and software engineering, the visitor design pattern is a way of separating an algorithm from an object structure on which it operates. A practical result of this separation is the ability to add new operations to existing object structures without modifying those...
might look like this in AspectJ:
This code snippet adds the
acceptVisitor
method to the Point
class.It is a requirement that any structural additions 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.
Implementation
AOP programs can affect other programs in two different ways, depending on the underlying languages and environments:- a combined program is produced, valid in the original language and indistinguishable from an ordinary program to the ultimate interpreter
- 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 process known as weaving - a special case of program transformation
Program transformation
A program transformation is any operation that takes a computer program and generates another program. In many cases the transformed program is required to be semantically equivalent to the original, relative to a particular formal semantics and in fewer cases the transformations result in programs...
. An aspect weaver
Aspect weaver
An aspect weaver is a metaprogramming utility for aspect-oriented languages designed to take instructions specified by aspects and generate the final implementation code. The weaver integrates aspects into the locations specified by the software as a pre-compilation step...
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 which method of combination is used.
Systems can implement source-level weaving using preprocessors (as C++ was implemented originally in CFront
Cfront
Cfront was the original compiler for C++ from around 1983, which converted C++ to C; developed by Bjarne Stroustrup. The preprocessor did not understand all of the language and much of the code was written via translations. Cfront had a complete parser, built symbol tables, and built a tree for...
) 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
AspectJ
AspectJ is an aspect-oriented extension created at PARC for the Java programming language. It is available in Eclipse Foundation open-source projects, both stand-alone and integrated into Eclipse. AspectJ has become the widely-used de-facto standard for AOP by emphasizing simplicity and usability...
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
AspectWerkz
AspectWerkz is a dynamic, lightweight and high-performance AOP/AOSD framework for Java. It has been merged with the AspectJ project, which supports AspectWerkz functionality since AspectJ 5....
in 2005.
Any solution that combines programs at runtime has to 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 "Problems", below).
Deploy-time weaving offers another approach. This basically implies post-processing, but rather than patching the generated code, this weaving approach subclasses existing classes so that the modifications are introduced by method-overriding. The existing classes remain untouched, even at runtime, and all existing tools (debuggers, profilers, etc.) can be used during development. A similar approach has already proven itself in the implementation of many Java EE application servers, such as IBM
IBM
International Business Machines Corporation or IBM is an American multinational technology and consulting corporation headquartered in Armonk, New York, United States. IBM manufactures and sells computer hardware and software, and it offers infrastructure, hosting and consulting services in areas...
's WebSphere
WebSphere
IBM WebSphere refers to a brand of computer software products in the genre of enterprise software known as "application and integration middleware". These software products are used by end-users to create applications and integrate applications with other applications...
.
Terminology
Standard terminology used in Aspect-oriented programming may include:- Cross-cutting concerns: Even though most classes in an OO model will perform a single, specific function, they often share common, secondary requirements with other classes. For example, we may want to add logging to classes within the data-access layer and also to classes in the UI layer whenever a thread enters or exits a method. Even though each class has a very different primary functionality, the code needed to perform the secondary functionality is often identical.
- Advice: This is the additional code that you want to apply to your existing model. In our example, this is the logging code that we want to apply whenever the thread enters or exits a method.
- Pointcut: This is the term given 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: 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 out of object-oriented programmingObject-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...
and computational reflection. AOP languages have functionality similar to, but more restricted than metaobject protocols
Metaobject
In computer science, a metaobject or meta-object is any entity that manipulates, creates, describes, or implements other objects. The object that the metaobject is about is called the base object...
. Aspects relate closely to programming concepts like subjects
Subjects (programming)
In computer programming within the subject-oriented programming paradigm, subjects are a way to separate concerns. For example, in a Shape class with two methods Draw and Move, each method would be considered a subject.-External links:*...
, mixin
Mixin
In object-oriented programming languages, a mixin is a class that provides a certain functionality to be inherited or just reused by a subclass, while not meant for instantiation , Mixins are synonymous functionally with abstract base classes...
s, and delegation
Delegation (programming)
In object-oriented programming, there are two related notions of delegation.* Most commonly, it refers to a programming language feature making use of the method lookup rules for dispatching so-called self-calls as defined by Lieberman in his 1986 paper "Using Prototypical Objects to Implement...
. Other ways to use aspect-oriented programming paradigms include Composition Filters and the 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 crosscutting specifications provide written in one place.
Designers have considered alternative ways to achieve separation of code, such as C#'s partial types, but such approaches lack a quantification mechanism that allows reaching several join points of the code with one declarative statement.
Adoption issues
Programmers need to be able to read code and understand what is happening in order to prevent errors.Even with proper education, understanding crosscutting concerns can be difficult without proper support for visualizing both static structure and the dynamic flow of a program. Beginning in 2002, AspectJ began to provide IDE plug-ins to support the visualizing of crosscutting concerns. Those features, as well as aspect code assist and refactoring are now common.
Given the power of AOP, if a programmer makes a logical mistake in expressing crosscutting, it can lead to widespread program failure. Conversely, another programmer may change the join points in a program – e.g., by renaming or moving methods – in ways that the aspect writer did not anticipate, with unintended consequence
Unintended consequence
In the social sciences, unintended consequences are outcomes that are not the outcomes intended by a purposeful action. The concept has long existed but was named and popularised in the 20th century by American sociologist Robert K. Merton...
s. One advantage of modularizing crosscutting concerns is enabling one programmer to affect the entire system easily; as a result, such problems present as a conflict over responsibility between two or more developers for a given failure. However, the solution for these problems can be much easier in the presence of AOP, since only the aspect need be changed, whereas the corresponding problems without AOP can be much more spread out.
Implementations
The following programming languageProgramming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
s have implemented AOP, within the language, or as an external library:
- .NET Framework.NET FrameworkThe .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability...
languages (C# / VB.NETVisual Basic .NETVisual Basic .NET , is an object-oriented computer programming language that can be viewed as an evolution of the classic Visual Basic , which is implemented on the .NET Framework...
) - AutoHotkeyAutoHotkeyAutoHotkey is a free, open source macro-creation and automation software utility which allows users to automate repetitive tasks. Any application user interface can be modified by AutoHotkey...
- CC (programming language)C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
/ C++C++C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell... - COBOLCOBOLCOBOL is one of the oldest programming languages. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments....
- The CocoaCocoa (API)Cocoa is Apple's native object-oriented application programming interface for the Mac OS X operating system and—along with the Cocoa Touch extension for gesture recognition and animation—for applications for the iOS operating system, used on Apple devices such as the iPhone, the iPod Touch, and...
Objective-CObjective-CObjective-C is a reflective, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.Today, it is used primarily on Apple's Mac OS X and iOS: two environments derived from the OpenStep standard, though not compliant with it...
frameworks - ColdFusionColdFusionIn computing, ColdFusion is the name of a commercial rapid application development platform invented by Jeremy and JJ Allaire in 1995. ColdFusion was originally designed to make it easier to connect simple HTML pages to a database, by version 2 it had...
- Common LispCommon LispCommon Lisp, commonly abbreviated CL, is a dialect of the Lisp programming language, published in ANSI standard document ANSI INCITS 226-1994 , . From the ANSI Common Lisp standard the Common Lisp HyperSpec has been derived for use with web browsers...
- DelphiBorland DelphiEmbarcadero Delphi is an integrated development environment for console, desktop graphical, web, and mobile applications.Delphi's compilers use its own Object Pascal dialect of Pascal and generate native code for 32- and 64-bit Windows operating systems, as well as 32-bit Mac OS X and iOS...
- Delphi PrismDelphi PrismDelphi Prism is a rapid application development tool for the Microsoft .NET Framework and Mono, developed by RemObjects Software and distributed by Embarcadero Technologies....
- eE (verification language)e is a hardware verification language which is tailored to implementing highly flexible and reusable verification testbenches.- History :...
(IEEE 1647) - Emacs LispEmacs LispEmacs Lisp is a dialect of the Lisp programming language used by the GNU Emacs and XEmacs text editors . It is used for implementing most of the editing functionality built into Emacs, the remainder being written in C...
- Groovy
- HaskellHaskell (programming language)Haskell is a standardized, general-purpose purely functional programming language, with non-strict semantics and strong static typing. It is named after logician Haskell Curry. In Haskell, "a function is a first-class citizen" of the programming language. As a functional programming language, the...
- JavaJava (programming language)Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
- AspectJAspectJAspectJ is an aspect-oriented extension created at PARC for the Java programming language. It is available in Eclipse Foundation open-source projects, both stand-alone and integrated into Eclipse. AspectJ has become the widely-used de-facto standard for AOP by emphasizing simplicity and usability...
- AspectJ
- JavaScriptJavaScriptJavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....
- Logtalk
- Lua
- make
- ML
- PHPPHPPHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...
- Racket
- PerlPerlPerl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...
- PrologPrologProlog is a general purpose logic programming language associated with artificial intelligence and computational linguistics.Prolog has its roots in first-order logic, a formal logic, and unlike many other programming languages, Prolog is declarative: the program logic is expressed in terms of...
- PythonPython (programming language)Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
- RubyRuby (programming language)Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...
- SqueakSqueakThe Squeak programming language is a Smalltalk implementation. It is object-oriented, class-based and reflective.It was derived directly from Smalltalk-80 by a group at Apple Computer that included some of the original Smalltalk-80 developers...
SmalltalkSmalltalkSmalltalk is an object-oriented, dynamically typed, reflective programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human–computer symbiosis." It was designed and created in part for educational use, more so for constructionist... - UML 2.0
- XMLXMLExtensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....
See also
- Aspect-oriented software developmentAspect-oriented software developmentIn computing, Aspect-oriented software development is an emerging software development technology that seeks new modularizations of software systems in order to isolate secondary or supporting functions from the main program's business logic...
- Distributed AOPDistributed AOPAspect-Oriented Programming presents the principle of the separation of concerns, allowing less interdependence, and more transparency. Thereby, an aspect is a module that encapsulates a crosscutting concern, and it is composed of pointcuts and advice bodies...
- Attribute grammarAttribute grammarAn attribute grammar is a formal way to define attributes for the productions of a formal grammar, associating these attributes to values. The evaluation occurs in the nodes of the abstract syntax tree, when the language is processed by some parser or compiler....
, a formalism that can be used for aspect-oriented programming on top of functional programming languages - Programming paradigmProgramming paradigmA programming paradigm is a fundamental style of computer programming. Paradigms differ in the concepts and abstractions used to represent the elements of a program and the steps that compose a computation A programming paradigm is a fundamental style of computer programming. (Compare with a...
s - Stability ModelStability ModelStability Model is a method of designing and modelling software. It is an extension of Object Oriented Software Design methodology, like UML, but adds its own set of rules, guidelines, procedures, and heuristics to achieve a more advanced Object Oriented software.The motivation is to achieve a...
- Subject-oriented programmingSubject-oriented programmingIn computing, Subject-Oriented Programming is an object-oriented software paradigm in which the state and behavior of objects are not seen as intrinsic to the objects themselves, but are provided by various subjective perceptions of the objects...
, an alternative to Aspect-oriented programming - Executable UMLExecutable UMLExecutable UML, often abbreviated to xtUML or xUML, "is a single language in the UML family, designed to define the semantics of subject matters precisely." Executable UML is the evolution of the Shlaer-Mellor method to UML...
- COMEFROMCOMEFROMIn computer programming, COMEFROM is an obscure control flow structure used in some programming languages, originally as a joke....
: Some elements of aspect-oriented programming have been compared to the joke COMEFROMCOMEFROMIn computer programming, COMEFROM is an obscure control flow structure used in some programming languages, originally as a joke....
statement.
- Decorator patternDecorator patternIn object-oriented programming, the decorator pattern is a design pattern that allows behaviour to be added to an existing object dynamically.-Introduction:...
- Domain-driven designDomain-driven designDomain-driven design is an approach to developing software for complex needs by deeply connecting the implementation to an evolving model of the core business concepts...
Further reading
The paper generally considered to be the authoritative reference for AOP.- Aspect-oriented Software Development and PHP, Dmitry Sheiko, 2006
- "Adaptive Object-Oriented Programming Using Graph-Based Customization" – Lieberherr, Silva-Lepe, et al. - 1994
External links
- Eric Bodden's list of AOP tools in .net framework
- Programming Styles: Procedural, OOP, and AOP
- Programming Forum: Procedural, OOP, and AOP
- Aspect-Oriented Software Development, annual conference on AOP
- AOSD Wiki, Wiki on aspect-oriented software development
- AspectJ Programming Guide
- The AspectBench Compiler for AspectJ, another Java implementation
- Series of IBM developerWorks articles on AOP
- A detailed series of articles on basics of aspect-oriented programming and AspectJ
- What is Aspect-Oriented Programming?, introduction with RemObjects Taco
- Constraint-Specification Aspect Weaver
- Aspect- vs. Object-Oriented Programming: Which Technique, When?
- Gregor Kiczales, Professor of Computer Science, explaining AOP, video 57 min.
- Aspect Oriented Programming in COBOL
- Aspect-Oriented Programming in Java with Spring Framework
- Wiki dedicated to AOP methods on.NET
- AOP considered harmful (Forrester)
- Early Aspects for Business Process Modeling (An Aspect Oriented Language for BPMN)
- AOSD Graduate Course at Bilkent University
- Introduction to AOP - Software Engineering Radio Podcast Episode 106
- An Objective-C implementation of AOP by Szilveszter Molnar
- Apect-Oriented programming for iOS and OS X by Manuel Gebele