AOP or Aspect Oriented Programming
Aspect-oriented programming entails breaking down program logic into distinct parts (so-called concerns, cohesive areas of functionality). Nearly all programming paradigms support some level of grouping and encapsulation of concerns into separate, independent entities by providing abstractions (e.g., functions, procedures, modules, classes, methods) that can be used for implementing, abstracting and composing these concerns. But some concerns defy these forms of implementation and are called crosscutting concerns because they “cut across” multiple abstractions in a program.
Logging exemplifies a crosscutting concern because a logging strategy necessarily affects every logged part of the system. Logging thereby crosscuts all logged classes and methods.“
In a nut shell : AOP lets you add behaviour to code without needing to change the code. Magic.
A brilliant analysis of different language approaches here : http://www.garfieldtech.com/blog/language-tradeoffs
Aspect-oriented approaches emphasize Modifiability, Extensibility, and Expediency at the expense of Testability, Verifiability, and arguably Understandability.
- Joint points = Where some other code can jump in and change things.
- Pointcuts = The code that does the jumping in.
Stereotypical AOP examples
- Transaction boundaries
- Actually really easy, as it just replaces the method!
- Several libs / frameworks to do this :
- AOP in 50 LOC - https://github.com/briancavalier/aops2gx-2013/tree/master/src
- cujoJS’s meld - https://github.com/cujojs/meld
- Dojo’s dojo/aspect - http://dojotoolkit.org
- Twitter FlightJS - https://github.com/flightjs/flight
- dcl - https://github.com/uhop/dcl
They all work in basically the same kind of way, but have their own take on things.
Things like AOP
Much of Drupal’s modular power comes from its hook system, which really can be thought of as a AOP hack. Any module or code can offer up hook points (aka joint points).
Other modules can then implement these hooks (pointcuts).
HapiJS extension points
HapiJS’s server exposes what it called "extension points” (joint points) which are events fired buy the server at parts of the Request lifecycle.
You can write plugins which extend from these points. (pointcuts)