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
28
votes
6 answers

Simplest way to achieve automatic notification of property change

I know that there are solutions out there for implementing INotifyPropertyChanged, but none of them are as simple as: reference this library, create/add this attribute, done (I'm thinking Aspect-Oriented Programming here). Does anyone know of a…
Pat
  • 16,515
  • 15
  • 95
  • 114
28
votes
2 answers

execution Vs. call Join point

I have two different aspect classes to count the number of non-static method calls for an execution of a test program. The first aspect counts methods on "call" join points: pointcut methodCalls() : call (!static * test..*(..)); before():…
user1843337
  • 283
  • 1
  • 3
  • 5
28
votes
4 answers

AOP Exception Handling

I see that Guice and Spring use AOP Alliance under the hood for method interceptions, and I've been trying to figure out how to get AOP Alliance to intercept and handle certain exceptions so I don't have to keep writing the same code over and over…
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
27
votes
7 answers

What are the disadvantages of Aspect-Oriented Programming (AOP)?

What are the possible and critical disadvantages of Aspect-Oriented Programming? For example: cryptic debugging for newbies (readability impact)
user2427
  • 7,842
  • 19
  • 61
  • 71
25
votes
4 answers

Why doesn't AspectJ compile-time weaving of Spring's @Configurable work?

Update 5: I've downloaded the latest Spring ToolsSuite IDE based on the latest Eclipse. When I import my project as a Maven project, Eclipse/STS appears to use the Maven goals for building my project. This means AspectJ finally works correctly in…
Robert Campbell
  • 6,848
  • 12
  • 63
  • 93
25
votes
4 answers

Use of proxies in Spring AOP

I am reading a book, which talks about enabling AspectJ support in Spring AOP. Given below is a paragraph taken from the book: To enable AspectJ annotation support in the Spring IoC container, you only have to define an empty XML element…
user2434
  • 6,339
  • 18
  • 63
  • 87
25
votes
2 answers

AspectJ pointcuts - get a reference to the joinpoint class and name

I am using the @AspectJ style for writing aspects, to handle logging in our application. Basically I have a pointcut set up like so: @Pointcut("call(public * com.example..*(..))") public void logging() {} and then a before and after advice like…
smauel
  • 665
  • 1
  • 8
  • 14
25
votes
7 answers

What is the most common use for AOP in spring project

After reviewing the AOP pattern, I'm overwhelmed with the ways of how and what to use it for in my spring project. I'd like to use it as audit log system of all the financial business logic. It just seems to be easy to integrate. But I'd like to…
MatBanik
  • 26,356
  • 39
  • 116
  • 178
25
votes
6 answers

Anyone with Postsharp experience in production?

Has anyone out there used Postsharp AOP framework in a production environment? Are there any pitfalls? In order to do some logging etc, can Postsharp be used in conjunction with Log4Net? Any tutorials on using Postsharp with Web Apps and/or Log4Net…
Perpetualcoder
  • 13,501
  • 9
  • 64
  • 99
25
votes
2 answers

What are the different methods for injecting cross-cutting concerns?

What are the different methods for injecting cross-cutting concerns into a class so that I can minimize the coupling of the classes involved while keeping the code testable (TDD or otherwise)? For example, consider if I have a class that requires…
Stacy Vicknair
  • 1,631
  • 1
  • 13
  • 12
24
votes
1 answer

Aspectj with android library

I have a lib that use aspects and is available via maven, now I'm trying to use that lib in an android application. If I include this plug-in in the app gradle file, everything works fine, but my goal is to extract the classpath…
letz
  • 1,762
  • 1
  • 20
  • 40
24
votes
1 answer

How to change the return value by spring aop

I have a method with a return value in DAO layer, I want to change the return value by spring AOP, according different requirement,s and then send to corresponding method in SERVICE layer; but i don't know how to do so.
cleverUtd
  • 301
  • 1
  • 3
  • 9
23
votes
3 answers

How to get a dump of all local variables?

How can I get a dump of all local & session variables when an exception occurs? I was thinking of writing some sort of reflection based function that would interrogate the calling function & create a dump of variables & values. Is there an existing…
Skadoosh
  • 2,575
  • 8
  • 40
  • 53
23
votes
4 answers

How to specify single pointcut for multiple packages

I am using Aspect for logging activities in my spring mvc based application. I am using @controller annotations to define any controller in my application. I have two different controller in two different package say com.package1 contains…
Ketan
  • 2,612
  • 5
  • 31
  • 44
23
votes
4 answers

AOP Fundamentals

Aspect-oriented programming is a subject matter that has been very difficult for me to find any good information on. My old Software Engineering textbook only mentions it briefly (and vaguely), and the wikipedia and various other tutorials/articles…
Eugie
  • 1,403
  • 1
  • 12
  • 17