Def­i­n­i­tion:

Aspect Oriented Program­ming (AOP) is a pro­gram­ming par­a­digm where each appli­ca­tion can focus on its pri­mary func­tions and core con­cerns by encour­ag­ing greater mod­u­lar­ity and increas­ing sep­a­ra­tion of cross-cutting con­cerns (such as log­ging and authentication).

Pur­pose:

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 other con­cerns such as:

  • per­sis­tence — writ­ing to the data­base for example
  • trans­ac­tion han­dling – defin­ing trans­ac­tion scope and set­ting roll­back strat­egy, etc.
  • secu­rity — user authen­ti­ca­tion for example
  • log­ging — for audit­ing and debugging

So effec­tively you’re mix­ing mul­ti­ple domains with fine-grained inter­sec­tions and likely 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 concern
  • boil­er­plate code at every inter­sec­tion point – intro­duc­ing dupli­cated code and increas­ing the size of the code base and the blast radius of any change that are not related 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-cutting con­cerns into sin­gle units called aspects, each aspect encap­su­lates behav­iours that affect mul­ti­ple classes into reusable modules.

Part­ing 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 cover. Which inter­est­ingly, is the flip side of the same coin because you employ AOP when you don’t want to deal with cross-cutting 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­mented so that every­one is on the same page and there are few surprises.

Frame­works:

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

Share

One Response to “Buzzword Buster — AOP

  1. […] IO code. How­ever, for those of us who are using frame­works such as Post­Sharp to deal with cross-cutting con­cerns we now face a new chal­lenge – the aspects which we have come to rely upon no longer works the […]

Leave a Reply