Aspect-Oriented
by Gregor Kiczales
Origin
The founder of aspect-oriented programming (AOP) is Gregor Kiczales. In the 1990s, he and his team developed the concept of aspects and created the AspectJ language, which extended object-oriented programming (OOP) to better modularize code.
Historical Context
AOP emerged as a response to difficulties in code organization caused by cross-cutting concerns—behavior that affects many modules in a program, such as logging, security management, and error handling. In object-oriented programming, such functions are often hard to isolate in a single place. Kiczales and his colleagues proposed isolating these concerns into separate modules (aspects), which are then “woven” into the main program logic.
Aspect-oriented programming (AOP) provides tools to separate cross-cutting concerns into distinct modules called aspects, which can interact with and complement the base program code.
All AOP languages offer ways to isolate cross-cutting concerns into individual entities. Since AspectJ pioneered this field, the concepts it introduced have spread to most AOP languages.
AOP provides solutions for handling cross-cutting concerns, such as logging, transaction management, or security, which typically affect many parts of a program. AspectJ, one of the first and most widely adopted tools, implements these concepts for the Java language.
Key Concepts in AOP
-
Aspect: A module or class that implements cross-cutting concerns. Aspects alter the behavior of the rest of the code by applying advice at specified join points defined by a pointcut.
Aspects are the core elements in AOP that allow cross-cutting concerns to be injected into a program without modifying its source code. They can influence the program’s execution at specific points, ensuring flexibility and modularity.
-
Advice: Code to be executed at a join point. Advice can be executed before, after, or in place of a join point.
Advice specifies what code should be executed at a join point. It can run before, after, or instead of the main code, allowing additional functionality to be added without changing the original code.
-
Join Point: A point in the execution of the program where advice can be applied. Many AOP implementations allow method calls and field accesses to be treated as join points.
Join points are locations in the code where aspects can be applied. This can include method calls, field access, or even specific exceptions, providing precise control over where and how additional functionality is integrated.
-
Pointcut: A set of join points. The pointcut defines whether a given join point is appropriate for the given advice. The most convenient AOP implementations use the main language’s syntax (e.g., Java signatures in AspectJ) and allow reusing pointcuts through renaming and combining.
Pointcuts group join points together and define when and where an aspect should be applied. This powerful tool manages aspects and allows for reusable, adaptable solutions.
-
Introduction: The ability to modify the structure of a class or change inheritance hierarchies to add aspect functionality to external code. Typically implemented via some meta-object protocol.
Introduction allows aspects to change class structures, such as adding new methods or fields, thus enhancing the program while keeping the core code intact.
Examples of Languages
- AspectJ
- PostSharp (for C#)
- Spring AOP
aspect-oriented paradigm