phpAspect Logo

Chapter 1. Aspect-Oriented Programming

Programming evolutions

In order to always improve the modularization and the reuse of programs source code, Programming paradigms never ceased to be more and more abstract models. Object-Oriented Programming have shown very powerful abilities to modularize vertical concerns into single entities. Packages, classes, and methods all help programmers to encapsulate concerns into single entities. But although these methodologies can't successfully encapsulate horizontal concerns, also called crosscutting concerns, because they exist in many parts of the program.

Figure 1.1. Programming evolutions

Programming evolutions


So we can all ask ourselves: what will be the programming paradigm of tomorrow ?

Technical concerns in OOP

In Object-Oriented Programming, classes are often polluted by cross-cutting concerns (also called technical concerns) tangled with basic functionalities (also called the business logic concern). These cross-cutting concerns can by various: transactions, security, logging, persistence, session, etc.

Figure 1.2. In OOP, the business logic has strong dependencies with technicals technical modules addresses.

In OOP, the business logic has strong dependencies with technicals technical modules addresses.


This pollution has many symptoms:

  • Code tangling
  • Code scattering
  • Code comprehension
  • Code reusability
  • Code evolution

Aspect-Oriented Programming

In software engineering, the programming paradigms of aspect-oriented programming (AOP) attempt to aid programmers in the separation of these cross-cutting concerns. AOP is defining all mechanisms for:

  • Writing aspects as a new software entiy.
  • Weaving technical concerns on business logic.

Figure 1.3. Inversion of control in AOP.

Inversion of control in AOP.


An aspect has the following anatomy:

The joinpoint notion provides all the mechanisms to identify patterns in the program flow.

Figure 1.4. Examples of joinpoints.

Examples of joinpoints.



A pointcut is a logical composition of joinpoints.

Advices represents the injected code into poincuts. There are three kinds of advices:

Aspects can declare attributes, methods, constants and constructors that are owned by other types. These are called inter-type declarations.