Buzzword Buster — AOP


Aspect Orient­ed Program­ming (AOP) is a pro­gram­ming par­a­digm where each appli­ca­tion can focus on its pri­ma­ry func­tions and core con­cerns by encour­ag­ing greater mod­u­lar­i­ty and increas­ing sep­a­ra­tion of cross-cut­ting con­cerns (such as log­ging and authen­ti­ca­tion).


In any real-world appli­ca­tions, when you’re writ­ing code to address the prob­lem domain (say, book­ing an order) you might need to address oth­er con­cerns such as:

  • per­sis­tence — writ­ing to the data­base for exam­ple
  • trans­ac­tion han­dling – defin­ing trans­ac­tion scope and set­ting roll­back strat­e­gy, etc.
  • secu­ri­ty — user authen­ti­ca­tion for exam­ple
  • log­ging — for audit­ing and debug­ging

So effec­tive­ly you’re mix­ing mul­ti­ple domains with fine-grained inter­sec­tions and like­ly to end up with:

  • tan­gled code — mak­ing it more dif­fi­cult to work out what the code is doing to address the core con­cern
  • boil­er­plate code at every inter­sec­tion point – intro­duc­ing dupli­cat­ed code and increas­ing the size of the code base and the blast radius of any change that are not relat­ed to the prob­lem domain, e.g. chang­ing the per­sis­tence media..

AOP aims to address these prob­lems by sep­a­rat­ing cross-cut­ting con­cerns into sin­gle units called aspects, each aspect encap­su­lates behav­iours that affect mul­ti­ple class­es into reusable mod­ules.

Parting thoughts..

As far as I can think of, the only draw­back of AOP is that you no longer see all the behav­iours of your class when you open it and it requires knowl­edge of the whole sys­tem to know what else are hap­pen­ing under the cov­er. Which inter­est­ing­ly, is the flip side of the same coin because you employ AOP when you don’t want to deal with cross-cut­ting con­cerns all the time!

One of the ways to mit­i­gate this prob­lem is to build up a cul­ture in your team and stan­dard­ise how AOP is imple­ment­ed so that every­one is on the same page and there are few sur­pris­es.


Post­Sharp pro­vides a light­weight AOP frame­work for the .Net plat­form and is estab­lish­ing itself as the de fac­to stan­dard much like the way Aspec­tJ has done for Java.