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
603
votes
17 answers

Uncatchable ChuckNorrisException

Is it possible to construct a snippet of code in Java that would make a hypothetical java.lang.ChuckNorrisException uncatchable? Thoughts that came to mind are using for example interceptors or aspect-oriented programming.
Max Charas
  • 4,980
  • 3
  • 20
  • 40
270
votes
7 answers

What is aspect-oriented programming?

I understand object oriented programming, and have been writing OO programs for a long time. People seem to talk about aspect-oriented programming, but I've never really learned what it is or how to use it. What is the basic paradigm? This…
Sophie
  • 2,957
  • 3
  • 18
  • 14
230
votes
7 answers

Aspect Oriented Programming vs. Object-Oriented Programming

Like most developers here and in the entire world, I have been developing software systems using object-oriented programming (OOP) techniques for many years. So when I read that aspect-oriented programming (AOP) addresses many of the problems that…
yeradis
  • 5,235
  • 5
  • 25
  • 26
175
votes
5 answers

Cross cutting concern example

What is a good example of a cross-cutting concern? The medical record example on the wikipedia page seems incomplete to me. Specifically from this example, why would logging lead to code duplication (scattering)? (Besides simple calls such as…
jlars62
  • 7,183
  • 7
  • 39
  • 60
163
votes
16 answers

How do I intercept a method call in C#?

For a given class I would like to have tracing functionality i.e. I would like to log every method call (method signature and actual parameter values) and every method exit (just the method signature). How do I accomplish this assuming that: …
Journeyman
  • 1,633
  • 2
  • 12
  • 7
156
votes
10 answers

@AspectJ pointcut for all methods of a class with specific annotation

I want to monitor all public methods of all Classes with specified annotation (say @Monitor) (note: Annotation is at class level). What could be a possible pointcut for this? Note: I am using @AspectJ style Spring AOP.
Rejeev Divakaran
  • 4,384
  • 7
  • 36
  • 36
107
votes
18 answers

Spring AOP: What's the difference between JoinPoint and PointCut?

I'm learning Aspect Oriented Programming concepts and Spring AOP. I'm failing to understand the difference between a Pointcut and a Joinpoint - both of them seem to be the same for me. A Pointcut is where you apply your advice and a Joinpoint is…
Saurabh Patil
  • 4,170
  • 4
  • 32
  • 33
102
votes
9 answers

NOT using repository pattern, use the ORM as is (EF)

I always used Repository pattern but for my latest project I wanted to see if I could perfect the use of it and my implementation of “Unit Of Work”. The more I started digging I started asking myself the question: "Do I really need it?" Now this all…
Dejan.S
  • 18,571
  • 22
  • 69
  • 112
90
votes
5 answers

What is the best implementation for AOP in .Net?

There is a lot of AOP implementation in C#, VB.net. this is some of AOP Implementations: PostSharp Castle DynamicProxy LinFu LOOM.NET Aspect.NET Enterprise Library 3.0 Policy Injection Application Block AspectDNG DotSpect (.SPECT) The Spring.NET…
ecleel
  • 11,748
  • 15
  • 48
  • 48
71
votes
1 answer

Getting UndeclaredThrowableException instead of my own exception

I have the following code public Object handlePermission(ProceedingJoinPoint joinPoint, RequirePermission permission) throws AccessException, Throwable { System.out.println("Permission = " + permission.value()); if…
user373201
  • 10,945
  • 34
  • 112
  • 168
67
votes
5 answers

Telling IntelliJ IDEA which methods not to identify as unused

IntelliJ IDEA has a handy feature to detect unused methods and show them in grey, hinting a potential warning for dead code. Some methods, however, are not executed directly but via reflection. A good example would be @RequestMapping-annotated…
mindas
  • 26,463
  • 15
  • 97
  • 154
65
votes
5 answers

Java Aspect-Oriented Programming with Annotations

In a post entitled "AOP Fundamentals", I asked for a King's English explanation of what AOP is, and what it does. I received some very helpful answers and links to articles that helped fill me in on all the theory. But now AOP's got my full…
Eugie
  • 1,403
  • 1
  • 12
  • 17
64
votes
11 answers

What are the possible AOP use cases?

I'd like to make a picture of what are the possible cases for effective involvement of AOP in application design. All I have met so far is: logging-related security checks transaction management tweaking of a legacy application Anything else? (It…
Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
64
votes
3 answers

Tracking down cause of Spring's "not eligible for auto-proxying"

When you start messing around with Spring's auto-proxy stuff, you often run into this behaviour as documented: Classes that implement the BeanPostProcessor interface are special, and so they are treated differently by the container. All …
skaffman
  • 398,947
  • 96
  • 818
  • 769
63
votes
6 answers

Google Guice vs. JSR-299 CDI / Weld

Weld, the JSR-299 Contexts and Dependency Injection reference implementation, considers itself as a kind of successor of Spring and Guice. CDI was influenced by a number of existing Java frameworks, including Seam, Guice and Spring. However, CDI…
deamon
  • 89,107
  • 111
  • 320
  • 448
1
2 3
99 100