Aspect-Oriented Programming

Aspect-Oriented Programming

« Back to Glossary Index
Visit Us
Follow Me

Aspect-Oriented Programming (AOP) is a programming paradigm that seeks to increase modularity by allowing the separation of cross-cutting concerns. It does so by adding additional behavior to existing code (an advice) without modifying the code itself, instead separately specifying which code is modified via a “pointcut” specification, such as “log all function calls when the function’s name begins with ‘set'”. This allows behaviors that are not central to the business logic (such as logging, persistence, or security) to be added to a program without cluttering the code that is central to the business logic. The core business logic can then remain free of these ancillary concerns, promoting cleaner, more modular code.

Key concepts in AOP include:

  1. Aspect: A modularization of a concern that cuts across multiple objects. Transaction management is a good example of a crosscutting concern in Java EE applications.
  2. Join point: A point during the execution of a program, such as the execution of a method or the handling of an exception. In Spring AOP, a join point always represents a method execution.
  3. Advice: Action taken by an aspect at a particular join point. Different types of advice include “around,” “before” and “after” advice.
  4. Pointcut: A predicate that matches join points. Advice is associated with a pointcut expression and runs at any join point matched by the pointcut.
  5. Target object: Object being advised by one or more aspects.

AOP can be used with object-oriented programming (OOP) and is seen as a supplement to, not a replacement for, OOP. By separating concerns in this manner, AOP can provide a cleaner and more understandable system, as well as one that is easier to update and maintain. Languages that support AOP include AspectJ (an extension to Java) and Spring (a framework for Java). Some programming environments also provide tools to support AOP-like techniques.

You may also like...