FACTOID # 99: Thinking of becoming a teacher? Head to Switzerland. Teaching salaries there start at $US 33,000.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Aspect oriented programming

In software engineering, the programming paradigm of aspect-oriented programming (AOP), also called aspect-oriented software development (AOSD), attempts to aid programmers in the separation of concerns, or the breaking down of a program into distinct parts that overlap in functionality as little as possible. In particular, AOP focuses on the modularization and encapsulation of cross-cutting concerns. Software engineering (SE) is the profession of people who create and maintain software applications by applying technologies and practices from computer science, project management, engineering, application domains and other fields. ... A programming paradigm is a paradigmatic style of programming (compare with a methodology, which is a paradigmatic style of doing software engineering). ... In computer science, separation of concerns (SoC) is the process of breaking a program into distinct features that overlap in functionality as little as possible. ... Modularity is a concept that has applications in the contexts of computer science, particularly programming, as well as cognitive science in investigating the structure of mind. ... Encapsulation may refer to: (in the vernacular) expressing an idea with few words, such as with an adage, proverb, slogan, or jingle (in software engineering) the process of enclosing programming elements inside a larger, more abstract entity, similar to information hiding and separation of concerns. ... In computer science, cross-cutting concerns, or crosscutting concerns, are aspects of a program, that do not relate to the core concerns directly, but are needed for proper program execution. ...


Gregor Kiczales and his team at Xerox PARC originated this concept. This team also developed the first, and still most popular, AOP language: AspectJ. Gregor Kiczales is a professor of computer science at the University of British Columbia in Canada. ... Bold text // Headline text Link title This article is about the computer research center. ... AspectJ is an aspect-oriented extension to the Java programming language created at Xerox PARC. An AspectJ compiler weaves aspects into Java bytecode to implement crosscutting concerns. ...


Older programming methodologies—including procedural programming and object-oriented programming—similarly focus on separation and encapsulation of concerns (or any area of interest of focus) into single entities. For example, procedures, packages, classes, and methods all help programmers encapsulate concerns into single entities. But although these methodologies can successfully encapsulate many software concerns, some concerns defy such easy encapsulation. Software engineers call these crosscutting concerns, because they exist in many parts of the program. This article or section does not cite its references or sources. ... In computer science, object-oriented programming, OOP for short, is a computer programming paradigm. ...


Logging offers the prototypical example of a crosscutting concern, because a logging strategy necessarily affects every single logged part of the system. Logging thereby crosscuts all logged classes, methods, and procedures. Data logging is the practice of recording, in some medium, sequential data, often in a time-associated format. ...


Typically, an implementation of an AOP language seeks to encapsulate these types of crosscutting concerns through the introduction of a new construct called an aspect. An aspect can alter the behavior of the base code (the non-aspect part of a program) by applying advice (additional behavior) over a quantification of join points (points in the structure or execution of a program), called a pointcut (a logical description of a set of join points). In computer science, an aspect is a part of a program that cross-cuts its core concerns, therefore violating its separation of concerns. ... In aspect-oriented programming a piece of advice describes a certain function, method or procedure that is to be applied at a given join point of a program. ... In computer science, a join point is a point in the flow of a program. ... In aspect-oriented computer programming, a pointcut is a set of join points. ...


In many AOP languages, method executions and field references all exemplify join points. A pointcut may consist, for example, of all references to a particular set of fields.

Contents


Motivation and basic concepts

Aspect-Oriented Programming has at its core the enabling of a better separation of concerns, by allowing the programmer to create cross-cutting concerns as first-class program modules. (Cross-cutting concerns are defined as those parts, or aspects, of the program that in standard design mechanisms end up scattered across multiple program modules, and tangled with other modules.)


For example, consider a banking application with a conceptually very simple method for transferring an amount from one account to another:

 void transfer(Account fromAccount, Account toAccount, int amount) { if (fromAccount.getBalance() < amount) { throw new InsufficientFundsException(); } fromAccount.withdraw(amount); toAccount.deposit(amount); } 

(the examples appear in a Java-like syntax, since at the time of writing, an overwhelming majority of AOP-related research and work takes place in Java or in Java-variants.) Java is an object-oriented programming language developed by James Gosling and colleagues at Sun Microsystems in the early 1990s. ...


However, in a real-world banking application, this transfer method seems far from adequate. We must include security checks to verify that the current user has the authorization to perform this operation. We must enclose the operation in a database transaction in order to prevent accidental data loss. We must log the operation to the system log. And so on. A very simplified version with all those new concerns would look somewhat like this: A database transaction is a unit of interaction with a database management system or similar system that is treated in a coherent and reliable way independent of other transactions that must be either entirely completed or aborted. ...

 void transfer(Account fromAccount, Account toAccount, int amount) { if (!getCurrentUser().canPerform(OP_TRANSFER)) { throw new SecurityException(); } if (amount < 0) { throw new NegativeTransferException(); } if (fromAccount.getBalance() < amount) { throw new InsufficientFundsException(); } Transaction tx = database.newTransaction(); try { fromAccount.withdraw(amount); toAccount.deposit(amount); tx.commit(); systemLog.logOperation(OP_TRANSFER, fromAccount, toAccount, amount); } catch(Exception e) { tx.rollback(); } } 

The code has lost its elegance and simplicity because the various new concerns have become tangled with the basic functionality (sometimes called the business logic concern). The transactions, security, logging, etc. all exemplify cross-cutting concerns.


Also 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.


Therefore, we find that unlike the core concerns of the system, the cross-cutting concerns do not get properly encapsulated in their own modules. This increases the system complexity and makes maintenance considerably more difficult.


AOP attempts to solve this problem by allowing the programmer to develop cross-cutting concerns as full stand-alone modules called aspects. In most AOP languages, an aspect is comprised of one or more pieces of advice (code snippets - like methods) and a list of join points (points in the main program into which the advice should be woven). For example, a security module can include an advice that performs a security check, with instructions to weave this code snippet into the beginning of methods a(), b() and c() of some class. Powerful mechanisms deploy to enable a broad specification of join points, so that developers need not enumerate weaving-destinations manually. These mechanisms are commonly known as pointcut specification languages.


Join Point Models

Fundamentally, the way an aspect interacts with the base program is defined by the join point model (JPM) that the aspect is written in. A JPM defines three things:

  • Where the aspect can apply. These are often called join points.
  • A way to specify (or quantify) multiple join points. These are often called pointcuts. Pointcuts are effectively a query over all the join points of a program to select a small sub-set of them.
  • A means of affecting behavior at the join points. In AspectJ, this is often called advice.

AspectJ has two JPMs: pointcuts and advice, and inter-type declarations. Other aspect languages have different JPMs. In computer science, a join point is a point in the flow of a program. ... In aspect-oriented computer programming, a pointcut is a set of join points. ... AspectJ is an aspect-oriented extension to the Java programming language created at Xerox PARC. An AspectJ compiler weaves aspects into Java bytecode to implement crosscutting concerns. ... In aspect-oriented programming a piece of advice describes a certain function, method or procedure that is to be applied at a given join point of a program. ...


The Pointcuts and Advice JPM in AspectJ

  • The join points in this JPM are well-defined points along the execution of a program. This can include: method execution, the instantiation of an object, and the throwing of an exception. Note that these join points are dynamic in nature and can only be discovered at runtime. Hence, the pointcuts and advice JPM in AspectJ is known as a dynamic join point model.
  • Pointcuts are specified by a query over the program. One such pointcut looks like this:
 pointcut set() : execution(* *.set*(..) ) && this(Point); 
This pointcut specifies all joinpoints corresponding to the execution of any method starting with set when the currently executing object is of type Point.
  • Advice is specified in a way that is similar to a method. However, advice is never explicitly invoked. It is only invoked when the pointcut attached to it is evaluated to true. Here is an example of this:
 after() : set() { Display.update(); }  
It says that after the set() pointcut evaluates to true execute the command(s) specified in the body of the advice.

Inter-Type Declarations in AspectJ

The second JPM in AspectJ is known as inter-type declarations. This is a mechanism that allows an aspect to add extra declarations to an existing class or object. This concept is known as open classes . An inter-type declaration using the visitor pattern looks like this: In object-oriented programming and software engineering, the visitor design pattern is a way of separating an algorithm from an object structure. ...

 aspect VisitAspect { Point.acceptVisitor(Visitor v) { v.visit(this); } } 
This code snippet adds the acceptVisitor method to the Point class.
  • The join points are all non-anonymous types in the program.
  • The pointcuts are the names of classes or interfaces.
  • The means of affecting change at the pointcuts are by adding body declarations to the type.

Other Join Point Models

There are other kinds of JPMs. All aspect languages can be defined in terms of their JPM. For example a hypothetical aspect language for UML may have the following JPM: The Unified Modeling Language (UML) is a non-proprietary, object modeling and specification language used in software engineering. ...

  • 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.

Weaving

Weaving - injecting the advice presented in aspects into the specified join-points associated with each advice - provides the final challenge of any AOP solution.


In the original introduction of AOP, Kiczales and his team listed the following possibilities for weaving:

  • a source preprocessor (similar to that in the original implementations of C++ )
  • a post-processor that patches binary files
  • an AOP-aware compiler that generates woven binary files
  • load-time weaving (for example, in the case of Java, weaving the relevant advice as each class gets loaded into the Java virtual machine (JVM))
  • run-time weaving (trap each join point at runtime, and execute all relevant advice)

The first two options complicate the development process, whereas the last two options may slow down the program's execution. The last option (run-time weaving) also requires a special aspect-aware execution environment. In the world of Java, this implies a special JVM or other supporting framework. In computer science, a preprocessor is a program that takes source code and performs transformations on it, before the step of compilation or interpretation. ... For a WikiBook on programming with C++, see Wikibooks: C++ Programming. ... A Java Virtual Machine (JVM), originally developed by Sun Microsystems, is a virtual machine that executes Java bytecode. ...


AspectJ currently uses a dedicated compiler solution. The compiler generates standard Java binary class files, which any standard JVM can execute. Load-time weaving will be added in an upcoming release as the result of the merger of AspectJ and AspectWerkz.


All of the listed weaving solutions (except the last) imply changing the code at some point; the code generated for a given Java class by the compiler (after processing and/or loading) does not equate to what a standard Java compiler would have generated, since it now contains woven pieces of advice code. Many view this as a major drawback of AOP, because it complicates both the programmer's understanding of the program execution model and the use of any standard, existing tools, such as debuggers (see also "Problems", below).


Cohen and Gil have produced a novel alternative: they present the notion of deploy-time weaving. This basically implies post-processing, but rather than patching the generated code, they suggest subclassing 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 J2EE application servers, such as IBM's WebSphere. Java 2 Platform, Enterprise Edition or J2EE is a Standard (albeit with no ISO or ECMA standard) for developing distributed Multi-tier architecture applications, based on modular components running on an application server. ... For other uses, see IBM (disambiguation). ... WebSphere refers to a brand of IBM software products, although the term also popularly refers to one specific product: WebSphere Application Server (WAS). ...


AspectJ: an AOP language

AspectJ is an aspect-oriented extension to the Java programming language. AspectJ is an aspect-oriented extension to the Java programming language created at Xerox PARC. An AspectJ compiler weaves aspects into Java bytecode to implement crosscutting concerns. ...


AOP and other programming paradigms

Aspects emerged out of object-oriented programming and computational reflection. AOP languages have functionality similar to, but more restricted than meta-object protocols. Aspects relate closely to programming concepts like subjects, mixins, and delegation. Other ways of using aspect-oriented programming paradigms include Composition Filters and the hyperslices approach. In computer science, object-oriented programming, OOP for short, is a computer programming paradigm. ... Metaobject is any entity that exhibits some aspects of objects, like type, interface, class, methods, attributes, variables, functions, control structures and many more. ... A way to separate concerns as subjects. ... In object-oriented programming languages, a mixin is an approach to implementing classes that differs from the most widely-used approach coming from the programming language Simula. ... In object-oriented programming there are two notions of delegation. ...


Problems for AOP

Debugging can become one of the greatest problems for AOP. While at the syntactic level AOP program code appears separate, at run-time it is not. Concern-weaving can become unpredictable if it is not specified which aspect should dominate. Designers have considered alternative ways to achieve separation of code, such as C#'s partial types. However, such approaches lack a quantification mechanism enabling programmers to reach several join points of the code with one declarative statement. Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program or a piece of electronic hardware thus making it behave as expected. ... From a theoretical point of view one can interpret the order of advice execution for an aspect-oriented program at a given joinpoint as a partial order: First we assume that all pieces of advice are around advice. ... C# (pronounced see-sharp) is an object-oriented programming language developed by Microsoft as part of their . ...


Another problem for AOP is the unintentional capture of joinpoints through wildcards. For example, suppose we specify a pointcut with associated advice as a wildcard on all methods that have a certain pattern to their spelling. A programmer who creates a new method may unwittingly choose a name to which the advice will - incorrectly - apply. Similarly, renaming a method can completely change its semantics. Must all programmers who modify the codebase over its lifetime learn a complex set of project-specific naming conventions in order to avoid such difficulties? An AOP-aware development environment can make the applicability of advice more visible, but it is an open question how such concerns will play out over the lifecycle of aspect-oriented code.


Implementations

  • For C#/VB.NET:
    • Puzzle.NAspect
    • AspectDNG
    • Aspect#
    • Encase
    • Compose*
    • Seasar.NET
    • DotSpect (.SPECT)
    • The Spring.NET Framework as part of its functionality
  • For Java:
    • AspectJ
    • AspectWerkz (Now merged with AspectJ)
    • Byte Code Engineering Library
    • CaesarJ
    • Dynaop
    • JAC
    • Jakarta Hivemind
    • Javassist Home Page
    • JAsCo
    • JAML
    • JBoss AOP
    • Object Teams
    • PROSE
    • Reflex
    • The AspectBench Compiler for AspectJ (abc)
    • The Spring Framework as part of its functionality
    • Seasar
    • The JMangler Project
    • InjectJ
  • For JavaScript:
    • AOP Fun with JavaScript
    • Dojo Toolkit
    • Aspectes
  • For C/C++:
    • AspectC++
    • XWeaver project
    • FeatureC++
  • For Lua:
    • AspectLua
  • For Python:
    • Lightweight Python AOP
    • Logilab's aspect module
    • Python/Transwarp AOP Tutorial (Replaced by PEAK)
    • PEAK
    • Pythius
  • For PHP:
    • PHPaspect
    • Aspect-Oriented PHP
    • Seasar.PHP
    • AOP API for PHP
    • AspectPHP
  • For Perl:
    • The Aspect Module
  • For XML:
    • AspectXML
  • For Squeak Smalltalk
    • AspectS

Write your own preprocessing system. C# (pronounced see-sharp) is an object-oriented programming language developed by Microsoft as part of their . ... // Headline text Visual Basic . ... Java is an object-oriented programming language developed by James Gosling and colleagues at Sun Microsystems in the early 1990s. ... Hivemind is a computer software framework, written in Java. ... JavaScript is the name of Netscape Communications Corporations implementation of ECMAScript, a scripting programming language based on the concept of prototypes. ... The C Programming Language, Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language The C programming language (often, just C) is a general-purpose, procedural, imperative computer programming language developed in the early 1970s by Dennis Ritchie for use... For a WikiBook on programming with C++, see Wikibooks: C++ Programming. ... The Lua (pronounced LOO-ah, or in IPA) programming language is a lightweight, reflective, imperative and procedural language, designed as a scripting language with extensible semantics as a primary goal. ... Python is an interpreted programming language created by Guido van Rossum in 1990. ... Ruby is a reflective, object-oriented programming language. ... PHP is an open-source, reflective programming language used mainly for producing dynamic web content and server-side applications. ... Perl, also Practical Extraction and Report Language (a backronym, see below) is a dynamic procedural programming language designed by Larry Wall and first released in 1987. ... Common Lisp, commonly abbreviated CL, is a dialect of the Lisp programming language, standardised by ANSI X3. ... A Cocoa application being developed using Xcode. ... The Extensible Markup Language (XML) is a W3C-recommended general-purpose markup language for creating special-purpose markup languages, capable of describing many different kinds of data. ... The Squeak programming language is a Smalltalk implementation, derived directly from Smalltalk-80, by Smalltalks originators, so it is object-oriented, and reflective. ... ColdFusion is the original and most common implementation of a tag and ECMAScript-based programming language -- ColdFusion Markup Language (CFML) and CFSCRIPT, respectively -- which is typically used in web application development for the generation of dynamic web pages. ... ActionScript is an ECMAScript-based programming language used for scripting Macromedia Flash movies and applications. ... COBOL is a third-generation programming language. ...

  • For More Info (real-world implementations):
    • AOSD.net

See also

A programming paradigm is a paradigmatic style of programming (compare with a methodology, which is a paradigmatic style of doing software engineering). ... To meet Wikipedias quality standards, this article or section may require cleanup. ... Executable UML, often abbreviated to xtUML or xUML, is a relatively new software development methodology and technology that is intended to enable Unified Modelling Language (UML) models to be translated or weaved into executable code such as Java bytecode or machine code. ... In computer programming, COMEFROM is a control flow structure used in some programming languages. ...

Publications

  • Kiczales, Gregor; John Lamping, Anurag Mendhekar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier, and John Irwin (1997). “Aspect-Oriented Programming”, Proceedings of the European Conference on Object-Oriented Programming, vol.1241, pp.220–242. The paper originating AOP.
  • Filman, Robert E.; Tzilla Elrad, Siobhan Clarke, and Mehmet Aksit. Aspect-Oriented Software Development. ISBN 0-32121-976-7.
  • Pawlak, Renaud; Lionel Seinturier, and Jean-Philippe Retaillé. Foundations of AOP for J2EE Development. ISBN 1-59059-507-6.
  • Laddad, Ramnivas. AspectJ in Action: Practical Aspect-Oriented Programming. ISBN 1-93011-093-6.
  • Jacobson, Ivar; and Pan-Wei Ng. Aspect-Oriented Software Development with Use Cases. ISBN 0-321-26888-1.
  • Aspect-oriented Software Development and PHP, Dmitry Sheiko, 2006

Detective Sergeant Siobhan Clarke is a detective in the Inspector Rebus series of novels by Scottish author Ian Rankin. ... Ivar Hjalmar Jacobson (born in Ystad, Sweden, on September 2, 1939) is a Swedish computer scientist. ...

External links

  • Aspect-Oriented Software Development (annual conference about AOP)
  • AOSD Wiki (Wiki specifically devoted to AOP)
  • AspectJ (Java implementation)
    • [1] more info on Inter-type member declarations mentioned above
  • AOPWorld.com (Source of information on AOP and its related technologies)
  • The AspectBench Compiler for AspectJ (another Java implementation)
  • A detailed series of articles about the basics of aspect-oriented programming and AspectJ
  • Introduction to Aspect Oriented Programming with RemObjects Taco
  • Constraint-Specification Aspect Weaver
  • Aspect- vs. Object-Oriented Programming: Which Technique, When?
  • Light-weight Approach to AOP for Python


 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments
Please enter the 5-letter protection code

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms.