Questions tagged [aop]

AOP stands for Aspect-Oriented Programming. Use this tag if your question is about aspect-oriented concepts and techniques, or for programming problems using AOP extensions in any language. AOP increases modularity by allowing the separation of "cross-cutting concerns" into aspects. Click learn more... to find out what it's all about.

AOP stands for aspect-oriented programming. Questions about aspect-oriented concepts, techniques, and programming problems using AOP extensions in any language should have this tag.

AOP exists because there are two types of requirements in software engineering: functional requirements (concerns) describe specific behaviors; non-functional requirements (cross-cutting concerns) describe general qualities or services. In OOP, concerns are implemented in a very modular way -- all of the code for a concern is kept together, usually in a class. This is a good thing because modular code increases software quality.

However, cross-cutting concerns cannot be modularized in OOP (that's why they're called "cross-cutting" because they 'cut across' the functional concerns). Code for a cross-cutting concern ends up being spread out (tangled) over many, or even all, of the modules in an OOP program. AOP fixes this problem by collecting that spread-out code into one module called an aspect.

Logging, caching, security, and transaction management are examples of cross-cutting concerns. AOP makes it straightforward to retrofit existing applications with any of these services. The original code is not modified. Instead, an aspect is created with advice and pointcuts. Advice is like a class method - it contains code with the new functionality to be added. A pointcut is code that selects one or more join points. Join points are specific places in the existing program where the advice will be applied. The new program is created during a process called weaving, when the original code and the aspect code are integrated with each other. Weaving can be done at compile-time or load-time, so you can add aspects to programs even when you don't have the source code (there are some restrictions, see here for example).

The most widely used AOP language is AspectJ, which is an aspect-oriented enhancement to Java. Using AOP in the Spring framework is also popular here on SO. AOP is accessible in a number of ways including command-line, Eclipse, Spring, and IntelliJ Ultimate. AOP is also available for several other languages: Python, JavaScript, Ruby, Lua, and Smalltalk.

AOP was first used in 1997 at Xerox PARC to solve the problem of tangled cross-cutting concerns in object-oriented programs.

AOP-related SO Tags:

3657 questions
31
votes
3 answers

Get AOP proxy from the object itself

Is possible to get the proxy of a given object in Spring? I need to call a function of a subclass. But, obviously, when I do a direct call, the aspects aren't applied. Here's an example: public class Parent { public doSomething() { …
sinuhepop
  • 20,010
  • 17
  • 72
  • 107
31
votes
1 answer

Will Spring support CDI?

Spring has been a good framework for DI and AOP for Java developers. Now, there comes a standard specification for DI and AOP which is CDI. Any good product can no longer stays good without supporting the relevant standards. (For example, Hibernate…
siva636
  • 16,109
  • 23
  • 97
  • 135
31
votes
7 answers

What can AOP do that OOP can't do?

I'm primarily a Java developer. I've met quite a few Java devs who love AOP. I've also been seeing more and more AOP "design patterns" emerging recently that seem to be fairly widely adopted. Even so, I'm still not convinced that AOP in OO code is a…
Daniel
  • 10,115
  • 3
  • 44
  • 62
31
votes
3 answers

Spring AOP: Getting parameters of the pointcut annotation

Consider I have defined the following aspect: @Aspect public class SampleAspect { @Around(value="@annotation(sample.SampleAnnotation)") public Object display(ProceedingJoinPoint joinPoint) throws Throwable { // ... } } and the…
Erik
  • 11,944
  • 18
  • 87
  • 126
31
votes
6 answers

Any AOP support library for Python?

I am trying to use some AOP in my Python programming, but I do not have any experience of the various libraries that exist. So my question are: What AOP support exists for Python? And what are the advantages of the differents libraries between…
edomaur
  • 1,397
  • 4
  • 23
  • 38
31
votes
2 answers

Spring AOP pointcut that matches annotation on interface

I have a service class implemented in Java 6 / Spring 3 that needs an annotation to restrict access by role. I have defined an annotation called RequiredPermission that has as its value attribute one or more values from an enum called…
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
31
votes
1 answer

What's aopalliance all about? And why is guice using it?

I'm using guice for dependency injection with aop from aopalliance. I can't quite figure out what's aopalliance all about and who implemented the version (dated from 2004) that's on their sourceforge page. Why is guice using this version instead of…
ivo
  • 4,101
  • 5
  • 33
  • 42
30
votes
2 answers

Get annotated parameters inside a pointcut

I have two annotation @LookAtThisMethod and @LookAtThisParameter, if I have a pointcut around the methods with @LookAtThisMethod how could I extract the parameters of said method which are annotated with @LookAtThisParameter? For…
Bobby
  • 18,217
  • 15
  • 74
  • 89
30
votes
3 answers

Aspect Oriented Programing (AOP) solutions for C# (.Net) and their features

I would like to ask for 3 information here: There is no integrated solution for Aspect Oriented Programing (AOP) in C# (.Net) from Microsoft is that correct ? Is there any such solution under development or planned ? What solutions are there that…
Rasto
  • 17,204
  • 47
  • 154
  • 245
30
votes
8 answers

How can I make external methods interruptable?

The Problem I'm running multiple invocations of some external method via an ExecutorService. I would like to be able to interrupt these methods, but unfortunately they do not check the interrupt flag by themselves. Is there any way I can force an…
Oak
  • 26,231
  • 8
  • 93
  • 152
30
votes
5 answers

What ever happened to Aspect Oriented Programming?

I remember that in the late 1990s and early 2000s Aspect Oriented Programming (AOP) was supposed to be the "Next Big Thing". Nowadays I see some AOP still around, but it seems to have faded into the background.
BubbaT
  • 1,810
  • 4
  • 21
  • 24
29
votes
3 answers

error Type referred to is not an annotation type:

I got the following Aspect @Around("execution(public * (@DisabledForBlockedAccounts *).*(..))" + " && @annotation(denyForTeam)") public Object translateExceptionsDenySelectedAccount(ProceedingJoinPoint pjp, Deny deny) throws Throwable { Account…
Acdc RocknRoll
  • 677
  • 5
  • 9
  • 16
29
votes
4 answers

Built-in AOP in C# - is it on the way?

In large apps I find myself really wishing I had built-in AOP facilities. As it stands in C# the best you can do is factories and RealProxys, PostSharp, ICorDebug, ICorProfiler or injection frameworks. There is no clean built-in way of doing AOP.…
Sam Saffron
  • 128,308
  • 78
  • 326
  • 506
29
votes
3 answers

Ruby dependency injection libraries

I've been looking at some Ruby dependency injection libraries. In particularly, I checked out Needle and Copland. They've been around for quite awhile, yet not a lot of usages. What are some of the pros and cons of using these two libraries? It…
newtonapple
  • 4,123
  • 3
  • 33
  • 31
29
votes
3 answers

Javascript AOP libraries

Which Javascript AOP library do you use, and what are its key features ?
glmxndr
  • 45,516
  • 29
  • 93
  • 118