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
59
votes
2 answers

Getting the java.lang.reflect.Method from a ProceedingJoinPoint?

The question is short and simple: Is there a way to get the Method object from an apsectj ProceedingJoinPoint? Currently I am doing Class[] parameterTypes = new Class[joinPoint.getArgs().length]; Object[] args = joinPoint.getArgs(); for(int i=0;…
Erik
  • 11,944
  • 18
  • 87
  • 126
58
votes
9 answers

How to make a simple dynamic proxy in C#

I want to build a dynamic proxy object to add certain functionality to an object. basically i want to receive an object, wrap it with an object that looks identical to the original i got, and intercept all the calls. class Wrapper : DynamicProxy//…
AK_
  • 7,981
  • 7
  • 46
  • 78
51
votes
14 answers

Aspect-oriented programming examples

Can anyone post an example of Aspect-oriented programming (AOP) that is not logging? I've looked at several resources but all the examples are trivial logging. What is it useful for?
Dave Hillier
  • 18,105
  • 9
  • 43
  • 87
51
votes
3 answers

spring autowired aop circular dependency

I'm using java config with @ComponentScanin order to initialize my beans and @EnableAspectJAutoProxy(proxyTargetClass=true)to use cglib proxies. In this project we have a lots of generated services autowired between them using @Autowired. It works…
Ignasi
  • 5,887
  • 7
  • 45
  • 81
50
votes
3 answers

What is AspectJ good for?

First let me note, that I use AspectJ and I like it, but what else can I do with it. I know AspectJ can be/is used for Logging. In some cases it is used for Transaction controlling – mostly implemented in conjunction with annotations. AspectJ can…
Ralph
  • 118,862
  • 56
  • 287
  • 383
49
votes
4 answers

Aspect Oriented Programming in C#

Are there any good resources to wrap my head around Aspect Oriented Programming? PS: I need to understand AO programming, not the libraries or frameworks available for .NET or C# :)
TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188
49
votes
1 answer

Unit testing Spring @Around AOP methods

I can unit test most of my Spring classes without needing to do Spring "stuff". I can unit test @Before advice methods without using Spring too: Example code: @Before("execution(* run(..)) && " + "" + "target(target) && " + …
slim
  • 40,215
  • 13
  • 94
  • 127
48
votes
9 answers

Performance impact of using aop

We have started to use spring aop for cross cutting aspects of our application (security & caching at the moment). My manager worries about the performance impact of this technology although he fully understands the benefits. My question, did you…
LiorH
  • 18,524
  • 17
  • 70
  • 98
48
votes
3 answers

RealProxy in dotnet core?

I'm working with the namespaces System.Runtime.Remoting.Proxies and System.Runtime.Remoting.Messaging for AOP in C#. I'm trying to port my application from .Net Framework 4.6 to dnxcore/dotnet core. Intellisense says, that these two namespaces are…
Matthias Burger
  • 5,549
  • 7
  • 49
  • 94
46
votes
6 answers

Is there any attribute relating to AJAX to be set for ASP.NET MVC controller actions?

I want to use partial views with AJAX calls in ASP.NET MVC, and this is the first time I'm using it. I just searched to see if there is anything special I should know beforehand, and one of'em that I'm curious about, is to see if there is any…
Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188
42
votes
3 answers

Authenticating the request header with Express

I want to verify that all our get requests have a specific token in their authentication header. I can add this to our get endpoints: app.get('/events/country', function(req, res) { if (!req.headers.authorization) { return res.json({ error:…
kambi
  • 3,291
  • 10
  • 37
  • 58
41
votes
6 answers

What is AOP, Dependency Injection and Inversion Of Control in Simple English

I have tried to understand AOP, Dependency Injection and Inversion of Control SPRING related concepts but I am having hard time understanding it. Can anyone explain this in simple English ?
Rachel
  • 100,387
  • 116
  • 269
  • 365
40
votes
3 answers

Performance cost of Java dynamic proxy

Many modern frameworks (Spring, Hibernate) provide very nice dynamic behaviors with use of Java dynamic proxies, but what's the exact performance cost associated with it? Are there public benchmarks available for Sun JVM?
Gennady Shumakher
  • 5,637
  • 12
  • 40
  • 45
38
votes
10 answers

Spring autowired bean for @Aspect aspect is null

I have the following spring configuration:
mogronalol
  • 2,946
  • 8
  • 38
  • 56
38
votes
11 answers

Do you use AOP (Aspect Oriented Programming) in production software?

AOP is an interesting programming paradigm in my opinion. However, there haven't been discussions about it yet here on stackoverflow (at least I couldn't find them). What do you think about it in general? Do you use AOP in your projects? Or do you…
Martin Klinke
  • 7,294
  • 5
  • 42
  • 64