Aspect Oriented Programming Sounds Scary

by EvanJPalmer

20u8wtc

When I started my new job a few days ago and was asked to learn Aspect Oriented Programming (AOP) I was scared. I thought it would be a big paradigm shift from Object Oriented Programming (OOP).

This is not true at all.

In a nutshell, all AOP is is creating attributes on Classes/Methods/Members/Events that help move common code out of the body of the method or class, helping to keep everything DRY and honoring the Single Responsibility Principle.

If you’ve written a custom attribute, you’ve done AOP*.

The meatier part of AOP is when you use a framework (like PostSharp). If you use a framework, the attributes have more knowledge of the caller. We can get arguments, return values and, method/class names (without costly reflection). We can even alter the flow of the method (or other) that was decorated with the attribute. We can also add compile-time options which don’t exist for regular custom attributes.

So to be 100% clear, as far as I can tell, AOP is a subset of OOP. You need to know how to program in OOP to be able to do AOP.

AOP cannot replace OOP – being a subset, AOP only does a subset of the work. It’s an idea for making you a better OOP developer.

AOP is not a difficult concept – and is pretty cool… and you’re already probably familiar with it if you’ve used/written attributes.

So relax. Have a beer. Don’t go in to work today. Why not watch a movie? Or old Jerry Springer episodes on YouTube?**

Also, stay tuned for more AOP stuff as I learn about it.

* I’m actually over simplyfying it here. I think technically, if you don’t have the cool shit that frameworks offer – like access to members, arguments, return values, compile-time overrirde- you’re probably not doing AOP. BUT the concept is so friggen similar, I’d argue little distinction needs to be made.

** Not actual advice. You should go to work.