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

AspectJ pointcut for annotated PRIVATE methods

I want to create a Pointcut for private methods that are annotated with a specific annotation. However my aspect is not triggered when the annotation is on a private method like below. @Aspect public class ServiceValidatorAspect { …
citress
  • 889
  • 3
  • 13
  • 35
14
votes
5 answers

AOP... Should I unlearn OOP?

I have skimmed the online documentation, read the wiki entry, the posts and the blogs, but I'm still puzzled. What is, in a nutshell, Aspect Oriented Programming ? Is it simply better then Object Oriented Programming ? Should I unlearn OOP ? If…
Philippe Carriere
  • 3,712
  • 4
  • 25
  • 46
14
votes
3 answers

Using Attributes to Call Methods

I have various individual methods which all need to perform the same functions before continuing on with their own implementation. Now I could implement these functions in each method, but I was wondering if there's a way to exploit attributes to do…
keyboardP
  • 68,824
  • 13
  • 156
  • 205
14
votes
2 answers

How to configure AspectJ with Load Time Weaving without Interface

On my project, I currently use AspectJ (not just Spring AOP due to some limitation) with the weaving at the Compile Time. In order to speed up the development on Eclipse, I want to do the weaving at the Load Time. I succeed to do that but with one…
13
votes
2 answers

How to unit test PostSharp aspects?

After asking this question about implementing an aspect with PostSharp, it came to my mind that I might have to update the code of this aspect in the future, and that I did not want to take the risk of breaking everything afterwards. So, I started…
remio
  • 1,242
  • 2
  • 15
  • 36
13
votes
2 answers

Applying Aspect Oriented Programming

I've been using some basic AOP style solutions for cross-cutting concerns like security, logging, validation, etc. My solution has revolved around Castle Windsor and DynamicProxy because I can apply everything using a Boo based DSL and keep my code…
Chris Canal
  • 4,824
  • 9
  • 35
  • 45
13
votes
5 answers

Understanding Spring AOP

I am working with Spring 3.0 framework and still a novice. Can anyone explain me in layman terms what is AOP programming? (a short example will definitely help) How does Spring incorporate/enhance/support it?
aces.
  • 3,902
  • 10
  • 38
  • 48
13
votes
3 answers

How to create an aspect on an Interface Method that extends from A "Super" Interface

I have a service-layer Interface that extends from a base Interface; I would like to create a Pointcut around my service-layer Interface, but on one of the methods defined in the base Interface. For instance.... I have a method in my base Interface…
El Guapo
  • 5,581
  • 7
  • 54
  • 82
13
votes
3 answers

Is there a way to wrap all JavaScript methods with a function?

I want to wrap every function call with some logging code. Something that would produce output like: func1(param1, param2) func2(param1) func3() func4(param1, param2) Ideally, I would like an API of the form: function globalBefore(func); function…
blake8086
  • 699
  • 8
  • 18
13
votes
3 answers

AspectJ Load time weaver doesn't detect all classes

I am using Spring's declarative transactions (the @Transactional annotation) in "aspectj" mode. It works in most cases exactly like it should, but for one it doesn't. We can call it Lang (because that's what it's actually called). I have been able…
waxwing
  • 18,547
  • 8
  • 66
  • 82
13
votes
3 answers

Aspect Oriented Programming in Qt

I'm trying to get my head around AOP and some Qt Code would really help. From wikipedia here is some sample code (easy for a Qt/C++ programmer to read): void transfer(Account fromAcc, Account toAcc, int amount, User user, Logger logger) throws…
Derick Schoonbee
  • 2,971
  • 1
  • 23
  • 39
13
votes
2 answers

Private member is suddenly null on API method call

Weird stuff going on: In my web api, I inject a repository into the controller upon resolving using Ninject. The repository gets stored in a private readonly member variable. Works perfectly fine! When a api method gets called, I access the variable…
xvdiff
  • 2,179
  • 2
  • 24
  • 47
13
votes
2 answers

Aspect Oriented Programming in Java WITHOUT AspectJ?

ok this question's never been asked before on the web so here goes: I'm learning Java (beginner-intermediate level) and I decided to go ahead of class programme by trying out Aspect-Oriented programming. Now this thing's supposed to be easy to learn…
user3578836
  • 139
  • 1
  • 6
13
votes
1 answer

The Old "@Transactional from within the same class" Situation

Synopsis of the original question: Using standard Spring Transactions with AOP proxying, it is not possible to call an @Transactional-marked method from a non-@Transactional-marked method in the same class and be within a transaction (specifically…
Random Human
  • 946
  • 1
  • 14
  • 31
12
votes
4 answers

PHP: Wrap all functions of a class in a subclass

Working with a PHP library class, and I'd like to wrap all of its public functions in a subclass... Something along the lines of: class BaseClass { function do_something() { some; stuff; } function do_something_else() …
mtbkrdave
  • 2,900
  • 3
  • 23
  • 24